diff options
author | Christian Brabandt <cb@256bit.org> | 2024-01-04 21:43:36 +0100 |
---|---|---|
committer | Christian Brabandt <cb@256bit.org> | 2024-01-04 22:11:33 +0100 |
commit | ad4d7f446dc6754bde212234d46f4849b520b6e0 (patch) | |
tree | 09a0bbf2eb0db04b87350aa728a3da32dd5f3dfd /src | |
parent | 184f71cc6868a240dc872ed2852542bbc1d43e28 (diff) |
patch 9.1.0007: can select empty inner text blocksv9.1.0007
Problem: can select empty inner text blocks
(laurentalacoque)
Solution: make selecting empty inner text blocks an error
textobjects: Make selecting inner empty blocks an error
fixes: #13514
closes: #13523
Signed-off-by: Christian Brabandt <cb@256bit.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/testdir/test_textobjects.vim | 114 | ||||
-rw-r--r-- | src/textobject.c | 5 | ||||
-rw-r--r-- | src/version.c | 2 |
3 files changed, 118 insertions, 3 deletions
diff --git a/src/testdir/test_textobjects.vim b/src/testdir/test_textobjects.vim index 746b3268b2..89e741c715 100644 --- a/src/testdir/test_textobjects.vim +++ b/src/testdir/test_textobjects.vim @@ -400,7 +400,7 @@ func Test_paragraph() call assert_beeps("normal Vipip") exe "normal \<C-C>" - close! + bw! endfunc " Tests for text object aw @@ -606,7 +606,7 @@ func Test_textobj_quote() normal $hhyi" call assert_equal('bar', @") - close! + bw! endfunc " Test for i(, i<, etc. when cursor is in front of a block @@ -638,7 +638,115 @@ func Test_textobj_find_paren_forward() normal 0di) call assert_equal('foo ()', getline(1)) - close! + bw! +endfunc + +func Test_inner_block_empty_paren() + new + call setline(1, ["(text)()", "", "(text)(", ")", "", "()()"]) + + " Example 1 + call cursor(1, 1) + let @" = '' + call assert_beeps(':call feedkeys("0f(viby","xt")') + call assert_equal(7, getpos('.')[2]) + call assert_equal('(', @") + + " Example 2 + call cursor(3, 1) + let @" = '' + call assert_beeps('call feedkeys("0f(viby", "xt")') + call assert_equal(7, getpos('.')[2]) + call assert_equal('(', @") + + " Example 3 + call cursor(6, 1) + let @" = '' + call assert_beeps('call feedkeys("0f(viby", "xt")') + call assert_equal(3, getpos('.')[2]) + call assert_equal('(', @") + bwipe! +endfunc + +func Test_inner_block_empty_bracket() + new + call setline(1, ["[text][]", "", "[text][", "]", "", "[][]"]) + + " Example 1 + call cursor(1, 1) + let @" = '' + call assert_beeps(':call feedkeys("0f[viby","xt")') + call assert_equal(7, getpos('.')[2]) + call assert_equal('[', @") + + " Example 2 + call cursor(3, 1) + let @" = '' + call assert_beeps('call feedkeys("0f[viby", "xt")') + call assert_equal(7, getpos('.')[2]) + call assert_equal('[', @") + + " Example 3 + call cursor(6, 1) + let @" = '' + call assert_beeps('call feedkeys("0f[viby", "xt")') + call assert_equal(3, getpos('.')[2]) + call assert_equal('[', @") + bwipe! +endfunc + +func Test_inner_block_empty_brace() + new + call setline(1, ["{text}{}", "", "{text}{", "}", "", "{}{}"]) + + " Example 1 + call cursor(1, 1) + let @" = '' + call assert_beeps(':call feedkeys("0f{viby","xt")') + call assert_equal(7, getpos('.')[2]) + call assert_equal('{', @") + + " Example 2 + call cursor(3, 1) + let @" = '' + call assert_beeps('call feedkeys("0f{viby", "xt")') + call assert_equal(7, getpos('.')[2]) + call assert_equal('{', @") + + " Example 3 + call cursor(6, 1) + let @" = '' + call assert_beeps('call feedkeys("0f{viby", "xt")') + call assert_equal(3, getpos('.')[2]) + call assert_equal('{', @") + bwipe! +endfunc + +func Test_inner_block_empty_lessthan() + new + call setline(1, ["<text><>", "", "<text><", ">", "", "<><>"]) + + " Example 1 + call cursor(1, 1) + let @" = '' + call assert_beeps(':call feedkeys("0f<viby","xt")') + call assert_equal(7, getpos('.')[2]) + call assert_equal('<', @") + + " Example 2 + call cursor(3, 1) + let @" = '' + call assert_beeps('call feedkeys("0f<viby", "xt")') + call assert_equal(7, getpos('.')[2]) + call assert_equal('<', @") + + " Example 3 + call cursor(6, 1) + let @" = '' + call assert_beeps('call feedkeys("0f<viby", "xt")') + call assert_equal(3, getpos('.')[2]) + call assert_equal('<', @") + bwipe! endfunc " vim: shiftwidth=2 sts=2 expandtab diff --git a/src/textobject.c b/src/textobject.c index d03b6244ed..af94d06bc8 100644 --- a/src/textobject.c +++ b/src/textobject.c @@ -1131,6 +1131,11 @@ current_block( break; } + if (EQUAL_POS(start_pos, *end_pos)) + // empty block like this: () + // there is no inner block to select, abort + return FAIL; + /* * In Visual mode, when the resulting area is not bigger than what we * started with, extend it to the next block, and then exclude again. diff --git a/src/version.c b/src/version.c index 3dc537d180..d00e80276c 100644 --- a/src/version.c +++ b/src/version.c @@ -705,6 +705,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 7, +/**/ 6, /**/ 5, |