]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 8.1.1405: "highlight" option of popup windows not supported v8.1.1405
authorBram Moolenaar <Bram@vim.org>
Sun, 26 May 2019 19:03:24 +0000 (21:03 +0200)
committerBram Moolenaar <Bram@vim.org>
Sun, 26 May 2019 19:03:24 +0000 (21:03 +0200)
Problem:    "highlight" option of popup windows not supported.
Solution:   Implement the "highlight" option.

runtime/doc/popup.txt
src/diff.c
src/option.c
src/popupwin.c
src/proto/option.pro
src/testdir/dumps/Test_popupwin_01.dump
src/testdir/dumps/Test_popupwin_03.dump
src/testdir/test_popupwin.vim
src/version.c

index af51885e4eee0740f3c715b8ba4d0669195672db..cc9b7d179e487dfb03a690f3684fa05f9b57e228 100644 (file)
@@ -322,8 +322,7 @@ The second argument of |popup_create()| is a dictionary with options:
        wrap            TRUE to make the lines wrap (default TRUE)
                        {not implemented yet}
        highlight       highlight group name to use for the text, stored in
-                       'wincolor'
-                       {not implemented yet}
+                       the 'wincolor' option
        border          list with numbers, defining the border thickness
                        above/right/below/left of the popup; an empty list
                        uses a border of 1 all around
index 7210ce2680df9ce451fde15ac6a19c3e66724626..0db2820f395f6c9cc887f21e4aa3f7e9320fb74a 100644 (file)
@@ -1447,18 +1447,14 @@ diff_win_options(
        wp->w_p_wrap_save = wp->w_p_wrap;
     wp->w_p_wrap = FALSE;
 # ifdef FEAT_FOLDING
-    curwin = wp;
-    curbuf = curwin->w_buffer;
     if (!wp->w_p_diff)
     {
        if (wp->w_p_diff_saved)
            free_string_option(wp->w_p_fdm_save);
        wp->w_p_fdm_save = vim_strsave(wp->w_p_fdm);
     }
-    set_string_option_direct((char_u *)"fdm", -1, (char_u *)"diff",
+    set_string_option_direct_in_win(wp, (char_u *)"fdm", -1, (char_u *)"diff",
                                                       OPT_LOCAL|OPT_FREE, 0);
-    curwin = old_curwin;
-    curbuf = curwin->w_buffer;
     if (!wp->w_p_diff)
     {
        wp->w_p_fdc_save = wp->w_p_fdc;
index 9b23eed58eccbb64188f1aae837df5369f36df5b..6bc1499f6ee9e36dba58c7ac48096478d1ee7b17 100644 (file)
@@ -5953,6 +5953,54 @@ set_string_option_direct(
     }
 }
 
+/*
+ * Like set_string_option_direct(), but for a window-local option in "wp".
+ * Blocks autocommands to avoid the old curwin becoming invalid.
+ */
+    void
+set_string_option_direct_in_win(
+       win_T           *wp,
+       char_u          *name,
+       int             opt_idx,
+       char_u          *val,
+       int             opt_flags,
+       int             set_sid)
+{
+    win_T      *save_curwin = curwin;
+
+    block_autocmds();
+    curwin = wp;
+    curbuf = curwin->w_buffer;
+    set_string_option_direct(name, opt_idx, val, opt_flags, set_sid);
+    curwin = save_curwin;
+    curbuf = curwin->w_buffer;
+    unblock_autocmds();
+}
+
+/*
+ * Like set_string_option_direct(), but for a buffer-local option in "buf".
+ * Blocks autocommands to avoid the old curbuf becoming invalid.
+ */
+    void
+set_string_option_direct_in_buf(
+       buf_T           *buf,
+       char_u          *name,
+       int             opt_idx,
+       char_u          *val,
+       int             opt_flags,
+       int             set_sid)
+{
+    buf_T      *save_curbuf = curbuf;
+
+    block_autocmds();
+    curbuf = buf;
+    curwin->w_buffer = curbuf;
+    set_string_option_direct(name, opt_idx, val, opt_flags, set_sid);
+    curbuf = save_curbuf;
+    curwin->w_buffer = curbuf;
+    unblock_autocmds();
+}
+
 /*
  * Set global value for string option when it's a local option.
  */
index 116efcb23f45049802d8a024abc6c240c6641e22..e39ee67d48917c44280bfeee36f8ab6ad748cf7d 100644 (file)
@@ -23,6 +23,7 @@
 apply_options(win_T *wp, buf_T *buf UNUSED, dict_T *dict)
 {
     int            nr;
+    char_u  *str;
 
     wp->w_maxwidth = dict_get_number(dict, (char_u *)"maxwidth");
     wp->w_maxheight = dict_get_number(dict, (char_u *)"maxheight");
@@ -52,6 +53,10 @@ apply_options(win_T *wp, buf_T *buf UNUSED, dict_T *dict)
     }
 #endif
 
+    str = dict_get_string(dict, (char_u *)"highlight", TRUE);
+    if (str != NULL)
+       set_string_option_direct_in_win(wp, (char_u *)"wincolor", -1,
+                                                  str, OPT_FREE|OPT_LOCAL, 0);
 }
 
 /*
@@ -94,12 +99,10 @@ f_popup_create(typval_T *argvars, typval_T *rettv)
     if (buf == NULL)
        return;
     ml_open(buf);
-    curbuf = buf;
-    set_string_option_direct((char_u *)"buftype", -1,
+    set_string_option_direct_in_buf(buf, (char_u *)"buftype", -1,
                                     (char_u *)"popup", OPT_FREE|OPT_LOCAL, 0);
-    set_string_option_direct((char_u *)"bufhidden", -1,
+    set_string_option_direct_in_buf(buf, (char_u *)"bufhidden", -1,
                                     (char_u *)"hide", OPT_FREE|OPT_LOCAL, 0);
-    curbuf = curwin->w_buffer;
     buf->b_p_ul = -1;      // no undo
     buf->b_p_swf = FALSE;   // no swap file
     buf->b_p_bl = FALSE;    // unlisted buffer
index 15aa0102e157228e11b127b2315483b133e43907..4a0da1cd44351da099ff8d14e6bbe27627584aa7 100644 (file)
@@ -21,6 +21,8 @@ int get_term_opt_idx(char_u **p);
 int set_term_option_alloced(char_u **p);
 int was_set_insecurely(char_u *opt, int opt_flags);
 void set_string_option_direct(char_u *name, int opt_idx, char_u *val, int opt_flags, int set_sid);
+void set_string_option_direct_in_win(win_T *wp, char_u *name, int opt_idx, char_u *val, int opt_flags, int set_sid);
+void set_string_option_direct_in_buf(buf_T *buf, char_u *name, int opt_idx, char_u *val, int opt_flags, int set_sid);
 int valid_spellang(char_u *val);
 char *check_colorcolumn(win_T *wp);
 char *check_stl_option(char_u *s);
index b3818c10a840e62109f4593bb3a6256bc31010a3..2a444cadc6df76692a6344a52d5c3c072931193b 100644 (file)
@@ -1,8 +1,8 @@
 >1+0&#ffffff0| @73
 |2| @73
-|3| @8|h+0&#5fd7ff255|e|l@1|o| |t|h|e|r|e| @8|r+0#0000001#ffd7ff255| |o|n|e| @8| +0#0000000#ffffff0@30
-|4| @22|a+0#0000001#ffd7ff255|n|o|t|h|e|r| |t|w|o| @8| +0#0000000#ffffff0@30
-|5| @22|a+0#0000001#ffd7ff255|n|o|t|h|e|r| |t|h|r|e@1| @6| +0#0000000#ffffff0@30
+|3| @8|h+0&#5fd7ff255|e|l@1|o| |t|h|e|r|e| @8|r+0&#afffff255| |o|n|e| @8| +0&#ffffff0@30
+|4| @22|a+0&#afffff255|n|o|t|h|e|r| |t|w|o| @8| +0&#ffffff0@30
+|5| @22|a+0&#afffff255|n|o|t|h|e|r| |t|h|r|e@1| @6| +0&#ffffff0@30
 |6| @73
 |7| @73
 |8| @73
index 7436a01768366bf681ddcda1712e7f3072090648..4f6f9ddc4ae7a89122d0e4d384a730371207c59f 100644 (file)
@@ -1,8 +1,8 @@
 | +2&#ffffff0|+| |[|N|o| |N|a|m|e|]| | +8#0000001#e0e0e08|[|N|o| |N|a|m|e|]| | +1#0000000#ffffff0@49|X+8#0000001#e0e0e08
 >1+0#0000000#ffffff0| @73
-|2| @8|h+0&#5fd7ff255|e|l@1|o| |t|h|e|r|e| @8|r+0#0000001#ffd7ff255| |o|n|e| @8| +0#0000000#ffffff0@30
-|3| @22|a+0#0000001#ffd7ff255|n|o|t|h|e|r| |t|w|o| @8| +0#0000000#ffffff0@30
-|4| @22|a+0#0000001#ffd7ff255|n|o|t|h|e|r| |t|h|r|e@1| @6| +0#0000000#ffffff0@30
+|2| @8|h+0&#5fd7ff255|e|l@1|o| |t|h|e|r|e| @8|r+0&#afffff255| |o|n|e| @8| +0&#ffffff0@30
+|3| @22|a+0&#afffff255|n|o|t|h|e|r| |t|w|o| @8| +0&#ffffff0@30
+|4| @22|a+0&#afffff255|n|o|t|h|e|r| |t|h|r|e@1| @6| +0&#ffffff0@30
 |5| @73
 |6| @73
 |7| @73
index b6b8a9eaac396a3990b2737ce83bb3f0455e2c9c..04c67a227a7a20858033e05d2e79e77b94daf7ce 100644 (file)
@@ -12,10 +12,11 @@ func Test_simple_popup()
   endif
   call writefile([
        \ "call setline(1, range(1, 100))",
-       \ "let winid = popup_create('hello there', {'line': 3, 'col': 11})",
-       \ "hi PopupColor ctermbg=lightblue",
-       \ "call setwinvar(winid, '&wincolor', 'PopupColor')",
+       \ "hi PopupColor1 ctermbg=lightblue",
+       \ "hi PopupColor2 ctermbg=lightcyan",
+       \ "let winid = popup_create('hello there', {'line': 3, 'col': 11, 'highlight': 'PopupColor1'})",
        \ "let winid2 = popup_create(['another one', 'another two', 'another three'], {'line': 3, 'col': 25})",
+       \ "call setwinvar(winid2, '&wincolor', 'PopupColor2')",
        \], 'XtestPopup')
   let buf = RunVimInTerminal('-S XtestPopup', {'rows': 10})
   call VerifyScreenDump(buf, 'Test_popupwin_01', {})
index 2b869f03dfe0aa5d0c34fada5f54670947572e02..04de1af85a360ed9524464f07fd28f821f7c6744 100644 (file)
@@ -767,6 +767,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    1405,
 /**/
     1404,
 /**/