]> granicus.if.org Git - vim/commitdiff
patch 8.1.2293: join adds trailing space when second line is empty v8.1.2293
authorBram Moolenaar <Bram@vim.org>
Tue, 12 Nov 2019 19:31:20 +0000 (20:31 +0100)
committerBram Moolenaar <Bram@vim.org>
Tue, 12 Nov 2019 19:31:20 +0000 (20:31 +0100)
Problem:    Join adds trailing space when second line is empty. (Brennan
            Vincent)
Solution:   Do not add a trailing space.

src/ops.c
src/testdir/test_join.vim
src/version.c

index 85e99f7eac4a48d577dda8c887a8925f86b2c6fc..258b27173ba258b9354e61a1733ae7a82d891186 100644 (file)
--- a/src/ops.c
+++ b/src/ops.c
@@ -1999,7 +1999,8 @@ do_join(
        if (insert_space && t > 0)
        {
            curr = skipwhite(curr);
-           if (*curr != ')' && currsize != 0 && endcurr1 != TAB
+           if (*curr != NUL && *curr != ')'
+                   && currsize != 0 && endcurr1 != TAB
                    && (!has_format_option(FO_MBYTE_JOIN)
                        || (mb_ptr2char(curr) < 0x100 && endcurr1 < 0x100))
                    && (!has_format_option(FO_MBYTE_JOIN2)
index 78835b2ccfd95ad5d6fc1d2453d9c0d7caaeac37..5801c2f1274a5d9fb2d868f4fd14181eee65ea98 100644 (file)
@@ -9,6 +9,27 @@ func Test_join_with_count()
   call setline(1, ['one', 'two', 'three', 'four'])
   normal 10J
   call assert_equal('one two three four', getline(1))
+
+  call setline(1, ['one', '', 'two'])
+  normal J
+  call assert_equal('one', getline(1))
+
+  call setline(1, ['one', ' ', 'two'])
+  normal J
+  call assert_equal('one', getline(1))
+
+  call setline(1, ['one', '', '', 'two'])
+  normal JJ
+  call assert_equal('one', getline(1))
+
+  call setline(1, ['one', ' ', ' ', 'two'])
+  normal JJ
+  call assert_equal('one', getline(1))
+
+  call setline(1, ['one', '', '', 'two'])
+  normal 2J
+  call assert_equal('one', getline(1))
+
   quit!
 endfunc
 
index 0e9b27be5d28d9d0da150ab1473bfcce699f9722..31133c53ee95d47dc4b6c9fad1893cab49bad5a5 100644 (file)
@@ -741,6 +741,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2293,
 /**/
     2292,
 /**/