]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.1240: Regression with ic/ac text objects and comment plugin v9.1.1240
authorMaxim Kim <habamax@gmail.com>
Wed, 26 Mar 2025 18:04:20 +0000 (19:04 +0100)
committerChristian Brabandt <cb@256bit.org>
Wed, 26 Mar 2025 18:05:35 +0000 (19:05 +0100)
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 <habamax@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/pack/dist/opt/comment/autoload/comment.vim
src/testdir/test_plugin_comment.vim
src/version.c

index 34f0d680a2757d29ae1b0ee0e7ae829f8b37f846..570080604c3feb9ab2dab99e86e235f8ce996414 100644 (file)
@@ -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)
index a0425d58d7dc9e053cd67c2acfa30566410fa9a7..b1d356be98f8d3f1aa5d1c386b6b7d40480fb954 100644 (file)
@@ -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 <expr> gC comment#Toggle()..''$''" ' .. input_file, {})
+
+  call term_sendkeys(buf, "fTgC")
+
+  let output_file = "comment_inline_test.vim"
+  call term_sendkeys(buf, $":w {output_file}\<CR>")
+  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 <expr> 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}\<CR>")
+  defer delete(output_file)
+
+  call StopVimInTerminal(buf)
+
+  let result = readfile(output_file)
+  call assert_equal(['echo "Hello" This should be a comment'], result)
+endfunc
index dcb428e45c24441d6a385431a073e005fb5f03d3..9ada5e0f9d350e9c15018c1bb54d04eddb1ddc53 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1240,
 /**/
     1239,
 /**/