From: Maxim Kim Date: Wed, 26 Mar 2025 18:04:20 +0000 (+0100) Subject: patch 9.1.1240: Regression with ic/ac text objects and comment plugin X-Git-Tag: v9.1.1240^0 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=08283b28afae1a75ddec1fad1b6dd1cb267aab12;p=thirdparty%2Fvim.git patch 9.1.1240: Regression with ic/ac text objects and comment plugin Problem: Regression with ic/ac text objects and comment plugin Solution: Fix regression, update tests (Maxim Kim) fix regression: sometimes ic/ac should be line-wise ``` int main() { // multilple comments // cursor is between them } # dac -> int main() { } ``` closes: #16947 closes: #16980 Signed-off-by: Maxim Kim Signed-off-by: Christian Brabandt --- diff --git a/runtime/pack/dist/opt/comment/autoload/comment.vim b/runtime/pack/dist/opt/comment/autoload/comment.vim index 34f0d680a2..570080604c 100644 --- a/runtime/pack/dist/opt/comment/autoload/comment.vim +++ b/runtime/pack/dist/opt/comment/autoload/comment.vim @@ -151,7 +151,7 @@ export def ObjComment(inner: bool) endif endif - if (pos_end[2] == (getline(pos_end[1])->len() ?? 1)) && pos_start[2] == 1 + if (pos_end[2] == (getline(pos_end[1])->len() ?? 1)) && pos_start[2] <= 1 cursor(pos_end[1], 1) normal! V cursor(pos_start[1], 1) diff --git a/src/testdir/test_plugin_comment.vim b/src/testdir/test_plugin_comment.vim index a0425d58d7..b1d356be98 100644 --- a/src/testdir/test_plugin_comment.vim +++ b/src/testdir/test_plugin_comment.vim @@ -457,7 +457,7 @@ func Test_textobj_cursor_on_leading_space_comment() let result = readfile(output_file) - call assert_equal(["int main() {", "", "}"], result) + call assert_equal(["int main() {", "}"], result) endfunc func Test_textobj_conseq_comment() @@ -514,3 +514,49 @@ func Test_textobj_conseq_comment2() call assert_equal(["int main() {", " printf(\"hello\");", "", " // world", " printf(\"world\");", "}"], result) endfunc + +func Test_inline_comment() + CheckScreendump + let lines =<< trim END + echo "Hello" This should be a comment + END + + let input_file = "test_inline_comment_input.vim" + call writefile(lines, input_file, "D") + + let buf = RunVimInTerminal('-c "packadd comment" -c "nnoremap gC comment#Toggle()..''$''" ' .. input_file, {}) + + call term_sendkeys(buf, "fTgC") + + let output_file = "comment_inline_test.vim" + call term_sendkeys(buf, $":w {output_file}\") + defer delete(output_file) + + call StopVimInTerminal(buf) + + let result = readfile(output_file) + call assert_equal(['echo "Hello" " This should be a comment'], result) +endfunc + +func Test_inline_uncomment() + CheckScreendump + let lines =<< trim END + echo "Hello" " This should be a comment + END + + let input_file = "test_inline_uncomment_input.vim" + call writefile(lines, input_file, "D") + + let buf = RunVimInTerminal('-c "packadd comment" -c "nnoremap gC comment#Toggle()..''$''" ' .. input_file, {}) + + call term_sendkeys(buf, '$F"gC') + + let output_file = "uncomment_inline_test.vim" + call term_sendkeys(buf, $":w {output_file}\") + defer delete(output_file) + + call StopVimInTerminal(buf) + + let result = readfile(output_file) + call assert_equal(['echo "Hello" This should be a comment'], result) +endfunc diff --git a/src/version.c b/src/version.c index dcb428e45c..9ada5e0f9d 100644 --- a/src/version.c +++ b/src/version.c @@ -704,6 +704,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ +/**/ + 1240, /**/ 1239, /**/