patch 9.1.1259: some issues with comment package and tailing spaces

Commit: 
https://github.com/vim/vim/commit/a580761a452a3c4aea8af6d7efb1edc373d303b4
Author: Maxim Kim <haba...@gmail.com>
Date:   Sun Mar 30 14:55:26 2025 +0200

    patch 9.1.1259: some issues with comment package and tailing spaces
    
    Problem:  some issues with comment package and tailing spaces
    Solution: correctly capture trailing spaces with the ac/ic text object
              (Maxim Kim)
    
    This commit fixes a few issues with the comment package:
    
    1) both ac and ic incorrectly miss the last //
    
    ```
    // hello trailing spaces
    //
    ```
    
    2) fix ac/ic with last empty comment line,
       vac should also select last line with #
    
    ```py
     # print("hello")
     # print("world")
     #
     #
    $endofbuffer$
    ```
    
    closes: #17013
    
    Signed-off-by: Maxim Kim <haba...@gmail.com>
    Signed-off-by: Christian Brabandt <c...@256bit.org>

diff --git a/runtime/pack/dist/opt/comment/autoload/comment.vim 
b/runtime/pack/dist/opt/comment/autoload/comment.vim
index 570080604..183351d19 100644
--- a/runtime/pack/dist/opt/comment/autoload/comment.vim
+++ b/runtime/pack/dist/opt/comment/autoload/comment.vim
@@ -1,7 +1,7 @@
 vim9script
 
 # Maintainer: Maxim Kim <haba...@gmail.com>
-# Last Update: 2025 Mar 21
+# Last Update: 2025-03-30
 #
 # Toggle comments
 # Usage:
@@ -107,8 +107,8 @@ export def ObjComment(inner: bool)
 
     # Search for the beginning of the comment block
     if IsComment()
-        if search(' %(\S+)|$', 'bW', 0, 200, IsComment) > 0
-            search(' %(\S)|$', 'W', 0, 200, () => !IsComment())
+        if search(' %(\S+)|%(^\s*$)', 'bW', 0, 200, IsComment) > 0
+            search(' %(\S)|%(^\s*$)', 'W', 0, 200, () => !IsComment())
         else
             cursor(1, 1)
             search(' \S+', 'cW', 0, 200)
@@ -130,11 +130,11 @@ export def ObjComment(inner: bool)
     if pos_init[1] > pos_start[1]
         cursor(pos_init[1], pos_init[2])
     endif
-    if search(' %(\S+)|$', 'W', 0, 200, IsComment) > 0
+    if search(' %(\S+)|%(^\s*$)', 'W', 0, 200, IsComment) > 0
         search('\S', 'beW', 0, 200, () => !IsComment())
     else
         if search('\%$', 'W', 0, 200) > 0
-            search('\ze\S', 'beW', 0, 200, () => !IsComment())
+            search('\ze\S', 'beW', line('.'), 200, () => !IsComment())
         endif
     endif
 
@@ -144,7 +144,7 @@ export def ObjComment(inner: bool)
         var spaces = matchstr(getline(pos_end[1]), '\%>.c\s*')
         pos_end[2] += spaces->len()
         if getline(pos_end[1])[pos_end[2] : ] =~ '^\s*$'
-            && (pos_start[2] == 1 || getline(pos_start[1])[ : pos_start[2]] =~ 
'^\s*$')
+            && (pos_start[2] <= 1 || getline(pos_start[1])[ : pos_start[2]] =~ 
'^\s*$')
             if search(' \s*\_$(\s*
)+', 'eW', 0, 200) > 0
                 pos_end = getcurpos()
             endif
diff --git a/src/testdir/test_plugin_comment.vim 
b/src/testdir/test_plugin_comment.vim
index 1068c84f9..992a4f1b5 100644
--- a/src/testdir/test_plugin_comment.vim
+++ b/src/testdir/test_plugin_comment.vim
@@ -485,6 +485,72 @@ func Test_textobj_noleading_space_comment2()
   call assert_equal(["int main() {", "}"], result)
 endfunc
 
+func Test_textobj_trailing_spaces_comment()
+  CheckScreendump
+  let lines = ['# print("hello")   ', '# print("world")   ', "#", 'print("!")']
+
+  let input_file = "test_textobj_trailing_spaces_input.py"
+  call writefile(lines, input_file, "D")
+
+  let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
+
+  call term_sendkeys(buf, "jdac")
+  let output_file = "comment_textobj_trailing_spaces_comment.py"
+  call term_sendkeys(buf, $":w {output_file}\<CR>")
+  defer delete(output_file)
+
+  call StopVimInTerminal(buf)
+
+  let result = readfile(output_file)
+
+  call assert_equal(['print("!")'], result)
+endfunc
+
+func Test_textobj_trailing_spaces_last_comment()
+  CheckScreendump
+  let lines = ['# print("hello")   ', '# print("world")   ', "#", '', '']
+
+  let input_file = "test_textobj_trailing_spaces_last_input.py"
+  call writefile(lines, input_file, "D")
+
+  let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
+
+  call term_sendkeys(buf, "jdac")
+  let output_file = "comment_textobj_trailing_spaces_last_comment.py"
+  call term_sendkeys(buf, $":w {output_file}\<CR>")
+  defer delete(output_file)
+
+  call StopVimInTerminal(buf)
+
+  let result = readfile(output_file)
+
+  call assert_equal([], result)
+endfunc
+
+func Test_textobj_last_line_empty_comment()
+  CheckScreendump
+  let lines =<< trim END
+    # print("hello")
+    #
+    #
+  END
+
+  let input_file = "test_textobj_last_line_empty_input.py"
+  call writefile(lines, input_file, "D")
+
+  let buf = RunVimInTerminal('-c "packadd comment" ' .. input_file, {})
+
+  call term_sendkeys(buf, "dac")
+  let output_file = "comment_textobj_last_line_empty_comment.py"
+  call term_sendkeys(buf, $":w {output_file}\<CR>")
+  defer delete(output_file)
+
+  call StopVimInTerminal(buf)
+
+  let result = readfile(output_file)
+
+  call assert_equal([], result)
+endfunc
 func Test_textobj_cursor_on_leading_space_comment()
   CheckScreendump
   let lines =<< trim END
diff --git a/src/version.c b/src/version.c
index 22357447f..e28782b3a 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 */
+/**/
+    1259,
 /**/
     1258,
 /**/

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/vim_dev/E1tysGl-007NhM-Mq%40256bit.org.

Raspunde prin e-mail lui