]> granicus.if.org Git - vim/commitdiff
patch 8.2.2542: highlight of char beyond line end is not correct v8.2.2542
authorBram Moolenaar <Bram@vim.org>
Mon, 22 Feb 2021 21:13:49 +0000 (22:13 +0100)
committerBram Moolenaar <Bram@vim.org>
Mon, 22 Feb 2021 21:13:49 +0000 (22:13 +0100)
Problem:    Highlight of char beyond line end is not correct. (Chuan Wei Foo)
Solution:   Fix counting NUL as one cell.  Draw one more character if the EOL
            is part of the match. (closes #7883)

src/match.c
src/testdir/dumps/Test_hlsearch_1.dump [new file with mode: 0644]
src/testdir/dumps/Test_hlsearch_2.dump [new file with mode: 0644]
src/testdir/test_search.vim
src/version.c

index 0df7bfe2fcae1e8d823e3580eeca5dd8c8cba3b7..f383d8a1a60143ea37b8c6a0d32507c2604a6f8e 100644 (file)
@@ -792,7 +792,15 @@ update_search_hl(
                        // highlight empty match, try again after
                        // it
                        if (has_mbyte)
-                           shl->endcol += (*mb_ptr2len)(*line + shl->endcol);
+                       {
+                           char_u *p = *line + shl->endcol;
+
+                           if (*p == NUL)
+                               // consistent with non-mbyte
+                               ++shl->endcol;
+                           else
+                               shl->endcol += (*mb_ptr2len)(p);
+                       }
                        else
                            ++shl->endcol;
                    }
@@ -842,18 +850,31 @@ get_prevcol_hl_flag(win_T *wp, match_T *search_hl, long curcol)
     int                prevcol_hl_flag = FALSE;
     matchitem_T *cur;                  // points to the match list
 
+#if defined(FEAT_PROP_POPUP)
+    // don't do this in a popup window
+    if (popup_is_popup(wp))
+       return FALSE;
+#endif
+
     // we're not really at that column when skipping some text
     if ((long)(wp->w_p_wrap ? wp->w_skipcol : wp->w_leftcol) > prevcol)
        ++prevcol;
 
-    if (!search_hl->is_addpos && prevcol == (long)search_hl->startcol)
+    // Highlight a character after the end of the line if the match started
+    // at the end of the line or when the match continues in the next line
+    // (match includes the line break).
+    if (!search_hl->is_addpos && (prevcol == (long)search_hl->startcol
+               || (prevcol > (long)search_hl->startcol
+                                             && search_hl->endcol == MAXCOL)))
        prevcol_hl_flag = TRUE;
     else
     {
        cur = wp->w_match_head;
        while (cur != NULL)
        {
-           if (!cur->hl.is_addpos && prevcol == (long)cur->hl.startcol)
+           if (!cur->hl.is_addpos && (prevcol == (long)cur->hl.startcol
+                       || (prevcol > (long)cur->hl.startcol
+                                                && cur->hl.endcol == MAXCOL)))
            {
                prevcol_hl_flag = TRUE;
                break;
diff --git a/src/testdir/dumps/Test_hlsearch_1.dump b/src/testdir/dumps/Test_hlsearch_1.dump
new file mode 100644 (file)
index 0000000..abcd91c
--- /dev/null
@@ -0,0 +1,6 @@
+|x+0&#ffff4012@2| | +0&#ffffff0@45
+>x+8&#ffff4012@2| | +8&#ffffff0@45
+|x+0&#ffff4012@2| | +0&#ffffff0@45
+|~+0#4040ff13&| @48
+|~| @48
+| +0#0000000&@31|2|,|1| @10|A|l@1| 
diff --git a/src/testdir/dumps/Test_hlsearch_2.dump b/src/testdir/dumps/Test_hlsearch_2.dump
new file mode 100644 (file)
index 0000000..0cb13c3
--- /dev/null
@@ -0,0 +1,6 @@
+|x+0&#ffff4012@2| | +0&#ffffff0@45
+|x+0&#ffff4012@2| | +0&#ffffff0@45
+>x+8&#ffff4012@2| | +8&#ffffff0@45
+|~+0#4040ff13&| @48
+|~| @48
+|/+0#0000000&|\|_|.|*| @26|3|,|1| @10|A|l@1| 
index 2dc53d97de428cf15f31e72586d55af82ec2eecc..5fed81c900fab187c0a8b5394fc41b873b698447 100644 (file)
@@ -944,6 +944,26 @@ func Test_incsearch_search_dump()
   call delete('Xis_search_script')
 endfunc
 
+func Test_hlsearch_dump()
+  CheckOption hlsearch
+  CheckScreendump
+
+  call writefile([
+       \ 'set hlsearch cursorline',
+        \ 'call setline(1, ["xxx", "xxx", "xxx"])',
+       \ '/.*',
+       \ '2',
+       \ ], 'Xhlsearch_script')
+  let buf = RunVimInTerminal('-S Xhlsearch_script', {'rows': 6, 'cols': 50})
+  call VerifyScreenDump(buf, 'Test_hlsearch_1', {})
+
+  call term_sendkeys(buf, "/\\_.*\<CR>")
+  call VerifyScreenDump(buf, 'Test_hlsearch_2', {})
+
+  call StopVimInTerminal(buf)
+  call delete('Xhlsearch_script')
+endfunc
+
 func Test_incsearch_substitute()
   CheckOption incsearch
 
index d6ee9bbb26b5bd4903aacd7cf7dc74b20735116b..757a14dfdd35313a596dce7948fe31316d0e75be 100644 (file)
@@ -750,6 +750,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    2542,
 /**/
     2541,
 /**/