aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzeertzjq <zeertzjq@outlook.com>2024-01-06 06:24:15 +0800
committerzeertzjq <zeertzjq@outlook.com>2024-01-06 06:25:37 +0800
commit14918118e86a7d113331f4445c51e6e48a6a99c4 (patch)
tree08ad93af5856730086f247868b3e1c1915184fbe
parentf38f86b1ad8ad2ae3236f36e56fcdb416f679e65 (diff)
downloadrneovim-14918118e86a7d113331f4445c51e6e48a6a99c4.tar.gz
rneovim-14918118e86a7d113331f4445c51e6e48a6a99c4.tar.bz2
rneovim-14918118e86a7d113331f4445c51e6e48a6a99c4.zip
vim-patch:9.1.0012: regression with empty inner blocks introduced
Problem: regression with empty inner blocks introduced (after v9.1.0007) Solution: Set correct cursor position, Check for visual mode being active (Maxim Kim) relates: vim/vim#13514 closes: vim/vim#13819 https://github.com/vim/vim/commit/3779516988f14f2070d827514c79383334a0946b Co-authored-by: Maxim Kim <habamax@gmail.com>
-rw-r--r--src/nvim/textobject.c7
-rw-r--r--test/old/testdir/test_textobjects.vim24
2 files changed, 25 insertions, 6 deletions
diff --git a/src/nvim/textobject.c b/src/nvim/textobject.c
index 3e696167e2..76ea24039a 100644
--- a/src/nvim/textobject.c
+++ b/src/nvim/textobject.c
@@ -955,9 +955,10 @@ int current_block(oparg_T *oap, int count, bool include, int what, int other)
}
}
- if (equalpos(start_pos, *end_pos)) {
- // empty block like this: ()
- // there is no inner block to select, abort
+ // In Visual mode, when resulting area is empty
+ // i.e. there is no inner block to select, abort.
+ if (equalpos(start_pos, *end_pos) && VIsual_active) {
+ curwin->w_cursor = old_pos;
return FAIL;
}
diff --git a/test/old/testdir/test_textobjects.vim b/test/old/testdir/test_textobjects.vim
index 72c7338a96..3b86ae97da 100644
--- a/test/old/testdir/test_textobjects.vim
+++ b/test/old/testdir/test_textobjects.vim
@@ -645,7 +645,7 @@ endfunc
func Test_inner_block_empty_paren()
new
- call setline(1, ["(text)()", "", "(text)(", ")", "", "()()"])
+ call setline(1, ["(text)()", "", "(text)(", ")", "", "()()", "", "text()"])
" Example 1
call cursor(1, 1)
@@ -667,12 +667,18 @@ func Test_inner_block_empty_paren()
call assert_beeps('call feedkeys("0f(viby", "xt")')
call assert_equal(3, getpos('.')[2])
call assert_equal('(', @")
+
+ " Change empty inner block
+ call cursor(8, 1)
+ call feedkeys("0cibtext", "xt")
+ call assert_equal("text(text)", getline('.'))
+
bwipe!
endfunc
func Test_inner_block_empty_bracket()
new
- call setline(1, ["[text][]", "", "[text][", "]", "", "[][]"])
+ call setline(1, ["[text][]", "", "[text][", "]", "", "[][]", "", "text[]"])
" Example 1
call cursor(1, 1)
@@ -694,12 +700,18 @@ func Test_inner_block_empty_bracket()
call assert_beeps('call feedkeys("0f[viby", "xt")')
call assert_equal(3, getpos('.')[2])
call assert_equal('[', @")
+
+ " Change empty inner block
+ call cursor(8, 1)
+ call feedkeys("0ci[text", "xt")
+ call assert_equal("text[text]", getline('.'))
+
bwipe!
endfunc
func Test_inner_block_empty_brace()
new
- call setline(1, ["{text}{}", "", "{text}{", "}", "", "{}{}"])
+ call setline(1, ["{text}{}", "", "{text}{", "}", "", "{}{}", "", "text{}"])
" Example 1
call cursor(1, 1)
@@ -721,6 +733,12 @@ func Test_inner_block_empty_brace()
call assert_beeps('call feedkeys("0f{viby", "xt")')
call assert_equal(3, getpos('.')[2])
call assert_equal('{', @")
+
+ " Change empty inner block
+ call cursor(8, 1)
+ call feedkeys("0ciBtext", "xt")
+ call assert_equal("text{text}", getline('.'))
+
bwipe!
endfunc