Skip to content

Commit 08283b2

Browse files
habamaxchrisbra
authored andcommitted
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 <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent f9f4e27 commit 08283b2

3 files changed

Lines changed: 50 additions & 2 deletions

File tree

runtime/pack/dist/opt/comment/autoload/comment.vim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ export def ObjComment(inner: bool)
151151
endif
152152
endif
153153

154-
if (pos_end[2] == (getline(pos_end[1])->len() ?? 1)) && pos_start[2] == 1
154+
if (pos_end[2] == (getline(pos_end[1])->len() ?? 1)) && pos_start[2] <= 1
155155
cursor(pos_end[1], 1)
156156
normal! V
157157
cursor(pos_start[1], 1)

src/testdir/test_plugin_comment.vim

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ func Test_textobj_cursor_on_leading_space_comment()
457457

458458
let result = readfile(output_file)
459459

460-
call assert_equal(["int main() {", "", "}"], result)
460+
call assert_equal(["int main() {", "}"], result)
461461
endfunc
462462

463463
func Test_textobj_conseq_comment()
@@ -514,3 +514,49 @@ func Test_textobj_conseq_comment2()
514514

515515
call assert_equal(["int main() {", " printf(\"hello\");", "", " // world", " printf(\"world\");", "}"], result)
516516
endfunc
517+
518+
func Test_inline_comment()
519+
CheckScreendump
520+
let lines =<< trim END
521+
echo "Hello" This should be a comment
522+
END
523+
524+
let input_file = "test_inline_comment_input.vim"
525+
call writefile(lines, input_file, "D")
526+
527+
let buf = RunVimInTerminal('-c "packadd comment" -c "nnoremap <expr> gC comment#Toggle()..''$''" ' .. input_file, {})
528+
529+
call term_sendkeys(buf, "fTgC")
530+
531+
let output_file = "comment_inline_test.vim"
532+
call term_sendkeys(buf, $":w {output_file}\<CR>")
533+
defer delete(output_file)
534+
535+
call StopVimInTerminal(buf)
536+
537+
let result = readfile(output_file)
538+
call assert_equal(['echo "Hello" " This should be a comment'], result)
539+
endfunc
540+
541+
func Test_inline_uncomment()
542+
CheckScreendump
543+
let lines =<< trim END
544+
echo "Hello" " This should be a comment
545+
END
546+
547+
let input_file = "test_inline_uncomment_input.vim"
548+
call writefile(lines, input_file, "D")
549+
550+
let buf = RunVimInTerminal('-c "packadd comment" -c "nnoremap <expr> gC comment#Toggle()..''$''" ' .. input_file, {})
551+
552+
call term_sendkeys(buf, '$F"gC')
553+
554+
let output_file = "uncomment_inline_test.vim"
555+
call term_sendkeys(buf, $":w {output_file}\<CR>")
556+
defer delete(output_file)
557+
558+
call StopVimInTerminal(buf)
559+
560+
let result = readfile(output_file)
561+
call assert_equal(['echo "Hello" This should be a comment'], result)
562+
endfunc

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,8 @@ static char *(features[]) =
704704

705705
static int included_patches[] =
706706
{ /* Add new patch number below this line */
707+
/**/
708+
1240,
707709
/**/
708710
1239,
709711
/**/

0 commit comments

Comments
 (0)