]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.1.0945: ComplMatchIns highlight doesn't end after inserted text v9.1.0945
authorzeertzjq <zeertzjq@outlook.com>
Wed, 18 Dec 2024 20:12:25 +0000 (21:12 +0100)
committerChristian Brabandt <cb@256bit.org>
Wed, 18 Dec 2024 20:12:25 +0000 (21:12 +0100)
Problem:  ComplMatchIns highlight doesn't end after inserted text.
Solution: Handle ComplMatchIns highlight more like search highlight.
          Fix off-by-one error. Handle deleting text properly.
          (zeertzjq)

closes: #16244

Signed-off-by: zeertzjq <zeertzjq@outlook.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
16 files changed:
src/drawline.c
src/highlight.c
src/insexpand.c
src/testdir/dumps/Test_pum_matchins_07.dump [new file with mode: 0644]
src/testdir/dumps/Test_pum_matchins_08.dump [new file with mode: 0644]
src/testdir/dumps/Test_pum_matchins_09.dump [new file with mode: 0644]
src/testdir/dumps/Test_pum_matchins_10.dump [new file with mode: 0644]
src/testdir/dumps/Test_pum_matchins_combine_01.dump [new file with mode: 0644]
src/testdir/dumps/Test_pum_matchins_combine_02.dump [new file with mode: 0644]
src/testdir/dumps/Test_pum_matchins_combine_03.dump [new file with mode: 0644]
src/testdir/dumps/Test_pum_matchins_combine_04.dump [new file with mode: 0644]
src/testdir/dumps/Test_pum_matchins_combine_05.dump [new file with mode: 0644]
src/testdir/dumps/Test_pum_matchins_combine_06.dump [new file with mode: 0644]
src/testdir/test_indent.vim
src/testdir/test_popup.vim
src/version.c

index 18857ee2e3eec5d64c5f7b1e8089f1964060c052..bc8e4d2ad7b8d4f9e4482d5e46da633d2240c121 100644 (file)
@@ -1172,7 +1172,8 @@ win_line(
     int                vi_attr = 0;            // attributes for Visual and incsearch
                                        // highlighting
     int                area_attr = 0;          // attributes desired by highlighting
-    int                search_attr = 0;        // attributes desired by 'hlsearch'
+    int                search_attr = 0;        // attributes desired by 'hlsearch' or
+                                       // ComplMatchIns
 #ifdef FEAT_SYN_HL
     int                vcol_save_attr = 0;     // saved attr for 'cursorcolumn'
     int                syntax_attr = 0;        // attributes desired by syntax
@@ -1213,7 +1214,7 @@ win_line(
     int                word_end = 0;           // last byte with same spell_attr
     int                cur_checked_col = 0;    // checked column for current line
 #endif
-    int                extra_check = 0;        // has extra highlighting
+    int                extra_check = FALSE;    // has extra highlighting
     int                multi_attr = 0;         // attributes desired by multibyte
     int                mb_l = 1;               // multi-byte byte length
     int                mb_c = 0;               // decoded multi-byte character
@@ -1868,6 +1869,9 @@ win_line(
     }
 #endif
 
+    if ((State & MODE_INSERT) && in_curline && ins_compl_active())
+       area_highlighting = TRUE;
+
 #ifdef FEAT_SYN_HL
     // Cursor line highlighting for 'cursorline' in the current window.
     if (wp->w_p_cul && lnum == wp->w_cursor.lnum)
@@ -2389,9 +2393,9 @@ win_line(
                        || (noinvcur && (colnr_T)wlv.vcol == wp->w_virtcol)))
                *area_attr_p = 0;               // stop highlighting
 
-#ifdef FEAT_SEARCH_EXTRA
            if (wlv.n_extra == 0)
            {
+#ifdef FEAT_SEARCH_EXTRA
                // Check for start/end of 'hlsearch' and other matches.
                // After end, check for start/end of next match.
                // When another match, have to check for start again.
@@ -2406,9 +2410,21 @@ win_line(
                // and bad things happen.
                if (*ptr == NUL)
                    has_match_conc = 0;
-           }
+#else
+               search_attr = 0;
 #endif
 
+               // Check if ComplMatchIns highlight is needed.
+               if ((State & MODE_INSERT) && in_curline && ins_compl_active())
+               {
+                   int ins_match_attr =
+                       ins_compl_col_range_attr((int)(ptr - line));
+                   if (ins_match_attr > 0)
+                       search_attr =
+                           hl_combine_attr(search_attr, ins_match_attr);
+               }
+           }
+
 #ifdef FEAT_DIFF
            if (wlv.diff_hlf != (hlf_T)0)
            {
@@ -2562,15 +2578,6 @@ win_line(
 #endif
        }
 
-       // Apply ComplMatchIns highlight if needed.
-       if (wlv.draw_state == WL_LINE
-               && (State & MODE_INSERT) && in_curline && ins_compl_active())
-       {
-           int ins_match_attr = ins_compl_col_range_attr((int)(ptr - line));
-           if (ins_match_attr > 0)
-               wlv.char_attr = hl_combine_attr(wlv.char_attr, ins_match_attr);
-       }
-
        // combine attribute with 'wincolor'
        if (wlv.win_attr != 0)
        {
index a4b2d48d2208378e477bff29082ec100b6bb8b5d..628ceb2593729885c1e9dddaebb483edafcbd26f 100644 (file)
@@ -262,7 +262,7 @@ static char *(highlight_init_both[]) = {
     "default link PmenuMatchSel PmenuSel",
     "default link PmenuExtra Pmenu",
     "default link PmenuExtraSel PmenuSel",
-    "default link ComplMatchIns Normal",
+    CENT("ComplMatchIns cterm=NONE", "ComplMatchIns gui=NONE"),
     CENT("Normal cterm=NONE", "Normal gui=NONE"),
     NULL
 };
index fd82b3655f83b2e40df856e23433fb83f3d87087..2d1490428b721c43b25f617bbc26ef88994825a1 100644 (file)
@@ -912,7 +912,7 @@ ins_compl_insert_bytes(char_u *p, int len)
     if (len == -1)
        len = (int)STRLEN(p);
     ins_bytes_len(p, len);
-    compl_ins_end_col = curwin->w_cursor.col - 1;
+    compl_ins_end_col = curwin->w_cursor.col;
 }
 
 /*
@@ -2437,7 +2437,7 @@ ins_compl_stop(int c, int prev_mode, int retval)
            int     compl_len = get_compl_len();
 
            if ((int)plen > compl_len)
-               ins_compl_insert_bytes(p + compl_len, (int)(plen - compl_len));
+               ins_compl_insert_bytes(p + compl_len, (int)plen - compl_len);
        }
        retval = TRUE;
     }
@@ -4264,6 +4264,7 @@ ins_compl_delete(void)
        if (stop_arrow() == FAIL)
            return;
        backspace_until_column(col);
+       compl_ins_end_col = curwin->w_cursor.col;
     }
 
     // TODO: is this sufficient for redrawing?  Redrawing everything causes
diff --git a/src/testdir/dumps/Test_pum_matchins_07.dump b/src/testdir/dumps/Test_pum_matchins_07.dump
new file mode 100644 (file)
index 0000000..bed5b51
--- /dev/null
@@ -0,0 +1,20 @@
+|α+0&#ffffff0|β|γ| |f+0#ff404010&|o@1> +0#0000000&|f|o@1| @63
+|~+0#4040ff13&| @1| +0#0000001#e0e0e08|f|o@1| @11| +0#4040ff13#ffffff0@55
+|~| @1| +0#0000001#ffd7ff255|b|a|r| @11| +0#4040ff13#ffffff0@55
+|~| @1| +0#0000001#ffd7ff255|你*&|好| +&@10| +0#4040ff13#ffffff0@55
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|-+2#0000000&@1| |O|m|n|i| |c|o|m|p|l|e|t|i|o|n| |(|^|O|^|N|^|P|)| |m+0#00e0003&|a|t|c|h| |1| |o|f| |3| +0#0000000&@34
diff --git a/src/testdir/dumps/Test_pum_matchins_08.dump b/src/testdir/dumps/Test_pum_matchins_08.dump
new file mode 100644 (file)
index 0000000..9f97b01
--- /dev/null
@@ -0,0 +1,20 @@
+|α+0&#ffffff0|β|γ| > |f|o@1| @66
+|~+0#4040ff13&| @1| +0#0000001#ffd7ff255|f|o@1| @11| +0#4040ff13#ffffff0@55
+|~| @1| +0#0000001#ffd7ff255|b|a|r| @11| +0#4040ff13#ffffff0@55
+|~| @1| +0#0000001#ffd7ff255|你*&|好| +&@10| +0#4040ff13#ffffff0@55
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|-+2#0000000&@1| |O|m|n|i| |c|o|m|p|l|e|t|i|o|n| |(|^|O|^|N|^|P|)| |B+0#e000002&|a|c|k| |a|t| |o|r|i|g|i|n|a|l| +0#0000000&@30
diff --git a/src/testdir/dumps/Test_pum_matchins_09.dump b/src/testdir/dumps/Test_pum_matchins_09.dump
new file mode 100644 (file)
index 0000000..9efdfcc
--- /dev/null
@@ -0,0 +1,20 @@
+|α+0&#ffffff0|β|γ| |你*0#ff404010&|好> +0#0000000&|f|o@1| @62
+|~+0#4040ff13&| @1| +0#0000001#ffd7ff255|f|o@1| @11| +0#4040ff13#ffffff0@55
+|~| @1| +0#0000001#ffd7ff255|b|a|r| @11| +0#4040ff13#ffffff0@55
+|~| @1| +0#0000001#e0e0e08|你*&|好| +&@10| +0#4040ff13#ffffff0@55
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|-+2#0000000&@1| |O|m|n|i| |c|o|m|p|l|e|t|i|o|n| |(|^|O|^|N|^|P|)| |m+0#00e0003&|a|t|c|h| |3| |o|f| |3| +0#0000000&@34
diff --git a/src/testdir/dumps/Test_pum_matchins_10.dump b/src/testdir/dumps/Test_pum_matchins_10.dump
new file mode 100644 (file)
index 0000000..867f935
--- /dev/null
@@ -0,0 +1,20 @@
+|α+0&#ffffff0|β|γ| |你*&|好> +&|f|o@1| @62
+|~+0#4040ff13&| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|1|,|1|4|-|9| @7|A|l@1| 
diff --git a/src/testdir/dumps/Test_pum_matchins_combine_01.dump b/src/testdir/dumps/Test_pum_matchins_combine_01.dump
new file mode 100644 (file)
index 0000000..2fe08fa
--- /dev/null
@@ -0,0 +1,20 @@
+|a+8&#40ff4011@2| |f|o@1> |b@2| @63
+|~+0#4040ff13#4040ff13| @1| +0#0000001#e0e0e08|f|o@1| @11| +0#4040ff13#4040ff13@55
+|~| @1| +0#0000001#ffd7ff255|b|a|r| @11| +0#4040ff13#4040ff13@55
+|~| @1| +0#0000001#ffd7ff255|你*&|好| +&@10| +0#4040ff13#4040ff13@55
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|-+2#0000000&@1| |O|m|n|i| |c|o|m|p|l|e|t|i|o|n| |(|^|O|^|N|^|P|)| |m+0#00e0003&|a|t|c|h| |1| |o|f| |3| +0#0000000&@34
diff --git a/src/testdir/dumps/Test_pum_matchins_combine_02.dump b/src/testdir/dumps/Test_pum_matchins_combine_02.dump
new file mode 100644 (file)
index 0000000..2a54238
--- /dev/null
@@ -0,0 +1,20 @@
+|a+8&#40ff4011@2| > |b@2| @66
+|~+0#4040ff13#4040ff13| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|1|,|5| @10|A|l@1| 
diff --git a/src/testdir/dumps/Test_pum_matchins_combine_03.dump b/src/testdir/dumps/Test_pum_matchins_combine_03.dump
new file mode 100644 (file)
index 0000000..a8c5c66
--- /dev/null
@@ -0,0 +1,20 @@
+|a+8&#40ff4011@2| |f+8#ffff4012#ff404010|o@1> +8#0000000#40ff4011|b@2| @63
+|~+0#4040ff13#4040ff13| @1| +0#0000001#e0e0e08|f|o@1| @11| +0#4040ff13#4040ff13@55
+|~| @1| +0#0000001#ffd7ff255|b|a|r| @11| +0#4040ff13#4040ff13@55
+|~| @1| +0#0000001#ffd7ff255|你*&|好| +&@10| +0#4040ff13#4040ff13@55
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|-+2#0000000&@1| |O|m|n|i| |c|o|m|p|l|e|t|i|o|n| |(|^|O|^|N|^|P|)| |m+0#00e0003&|a|t|c|h| |1| |o|f| |3| +0#0000000&@34
diff --git a/src/testdir/dumps/Test_pum_matchins_combine_04.dump b/src/testdir/dumps/Test_pum_matchins_combine_04.dump
new file mode 100644 (file)
index 0000000..667e1c9
--- /dev/null
@@ -0,0 +1,20 @@
+|a+8&#40ff4011@2| > |b@2| @66
+|~+0#4040ff13#4040ff13| @1| +0#0000001#ffd7ff255|f|o@1| @11| +0#4040ff13#4040ff13@55
+|~| @1| +0#0000001#ffd7ff255|b|a|r| @11| +0#4040ff13#4040ff13@55
+|~| @1| +0#0000001#ffd7ff255|你*&|好| +&@10| +0#4040ff13#4040ff13@55
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|-+2#0000000&@1| |O|m|n|i| |c|o|m|p|l|e|t|i|o|n| |(|^|O|^|N|^|P|)| |B+0#e000002&|a|c|k| |a|t| |o|r|i|g|i|n|a|l| +0#0000000&@30
diff --git a/src/testdir/dumps/Test_pum_matchins_combine_05.dump b/src/testdir/dumps/Test_pum_matchins_combine_05.dump
new file mode 100644 (file)
index 0000000..d241123
--- /dev/null
@@ -0,0 +1,20 @@
+|a+8&#40ff4011@2| |你*8#ffff4012#ff404010|好> +8#0000000#40ff4011|b@2| @62
+|~+0#4040ff13#4040ff13| @1| +0#0000001#ffd7ff255|f|o@1| @11| +0#4040ff13#4040ff13@55
+|~| @1| +0#0000001#ffd7ff255|b|a|r| @11| +0#4040ff13#4040ff13@55
+|~| @1| +0#0000001#e0e0e08|你*&|好| +&@10| +0#4040ff13#4040ff13@55
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|-+2#0000000&@1| |O|m|n|i| |c|o|m|p|l|e|t|i|o|n| |(|^|O|^|N|^|P|)| |m+0#00e0003&|a|t|c|h| |3| |o|f| |3| +0#0000000&@34
diff --git a/src/testdir/dumps/Test_pum_matchins_combine_06.dump b/src/testdir/dumps/Test_pum_matchins_combine_06.dump
new file mode 100644 (file)
index 0000000..2a54238
--- /dev/null
@@ -0,0 +1,20 @@
+|a+8&#40ff4011@2| > |b@2| @66
+|~+0#4040ff13#4040ff13| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|~| @73
+|-+2#0000000&@1| |I|N|S|E|R|T| |-@1| +0&&@44|1|,|5| @10|A|l@1| 
index 0cead5fb1962ab2b42bb0244172e5548d2d29b45..0f0f9da8beb280d8f0dd8db7eb0eb0bc5ca89044 100644 (file)
@@ -305,7 +305,7 @@ endfunc
 
 " Test that mouse shape is restored to Normal mode after using "gq" when
 " 'indentexpr' executes :normal.
-func Test_indent_norm_with_gq()
+func Test_mouse_shape_indent_norm_with_gq()
   CheckFeature mouseshape
   CheckCanRunGui
 
index 9ea5445ce21cf29d493de45f718229735692b496..8f053fab89ee49b8e8139dcaccdce9d73d1b3861 100644 (file)
@@ -1746,13 +1746,67 @@ func Test_pum_matchins_highlight()
   call TermWait(buf)
   call term_sendkeys(buf, "Sαβγ \<C-X>\<C-O>\<C-Y>")
   call VerifyScreenDump(buf, 'Test_pum_matchins_04', {})
-  call term_sendkeys(buf, "\<C-E>\<Esc>")
+  call term_sendkeys(buf, "\<Esc>")
 
   " restore after cancel completion
   call TermWait(buf)
   call term_sendkeys(buf, "Sαβγ \<C-X>\<C-O>\<Space>")
   call VerifyScreenDump(buf, 'Test_pum_matchins_05', {})
-  call term_sendkeys(buf, "\<C-E>\<Esc>")
+  call term_sendkeys(buf, "\<Esc>")
+
+  " text after the inserted text shouldn't be highlighted
+  call TermWait(buf)
+  call term_sendkeys(buf, "0ea \<C-X>\<C-O>")
+  call VerifyScreenDump(buf, 'Test_pum_matchins_07', {})
+  call term_sendkeys(buf, "\<C-P>")
+  call VerifyScreenDump(buf, 'Test_pum_matchins_08', {})
+  call term_sendkeys(buf, "\<C-P>")
+  call VerifyScreenDump(buf, 'Test_pum_matchins_09', {})
+  call term_sendkeys(buf, "\<C-Y>")
+  call VerifyScreenDump(buf, 'Test_pum_matchins_10', {})
+  call term_sendkeys(buf, "\<Esc>")
+
+  call StopVimInTerminal(buf)
+endfunc
+
+func Test_pum_matchins_highlight_combine()
+  CheckScreendump
+  let lines =<< trim END
+    func Omni_test(findstart, base)
+      if a:findstart
+        return col(".")
+      endif
+      return [#{word: "foo"}, #{word: "bar"}, #{word: "你好"}]
+    endfunc
+    set omnifunc=Omni_test
+    hi Normal ctermbg=blue
+    hi CursorLine cterm=underline ctermbg=green
+    set cursorline
+    call setline(1, 'aaa bbb')
+  END
+  call writefile(lines, 'Xscript', 'D')
+  let buf = RunVimInTerminal('-S Xscript', {})
+
+  " when ComplMatchIns is not set, CursorLine applies normally
+  call term_sendkeys(buf, "0ea \<C-X>\<C-O>")
+  call VerifyScreenDump(buf, 'Test_pum_matchins_combine_01', {})
+  call term_sendkeys(buf, "\<C-E>")
+  call VerifyScreenDump(buf, 'Test_pum_matchins_combine_02', {})
+  call term_sendkeys(buf, "\<BS>\<Esc>")
+
+  " when ComplMatchIns is set, it is applied over CursorLine
+  call TermWait(buf)
+  call term_sendkeys(buf, ":hi ComplMatchIns ctermbg=red ctermfg=yellow\<CR>")
+  call TermWait(buf)
+  call term_sendkeys(buf, "0ea \<C-X>\<C-O>")
+  call VerifyScreenDump(buf, 'Test_pum_matchins_combine_03', {})
+  call term_sendkeys(buf, "\<C-P>")
+  call VerifyScreenDump(buf, 'Test_pum_matchins_combine_04', {})
+  call term_sendkeys(buf, "\<C-P>")
+  call VerifyScreenDump(buf, 'Test_pum_matchins_combine_05', {})
+  call term_sendkeys(buf, "\<C-E>")
+  call VerifyScreenDump(buf, 'Test_pum_matchins_combine_06', {})
+  call term_sendkeys(buf, "\<Esc>")
 
   call StopVimInTerminal(buf)
 endfunc
index ebaca6e8fc111dbf83d34f9a92a1fef97582bc28..f18772d1814270db82797b4bcdacf50fec65a917 100644 (file)
@@ -704,6 +704,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    945,
 /**/
     944,
 /**/