comparison src/popupwin.c @ 17440:a5874fdc8f3a v8.1.1718

patch 8.1.1718: popup menu highlighting does not look good commit https://github.com/vim/vim/commit/cb5ff34c1b8a89fcdb86653ab18d0aa53f665642 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jul 20 16:51:19 2019 +0200 patch 8.1.1718: popup menu highlighting does not look good Problem: Popup menu highlighting does not look good. Solution: Highlight the whole window line. Fix that sign line HL is not displayed in a window with a background color.
author Bram Moolenaar <Bram@vim.org>
date Sat, 20 Jul 2019 17:00:08 +0200
parents ce35cdbe9f74
children 57b9fca8c7d2
comparison
equal deleted inserted replaced
17439:8be5444ee2cb 17440:a5874fdc8f3a
449 { 449 {
450 if (wp->w_cursor.lnum < wp->w_topline) 450 if (wp->w_cursor.lnum < wp->w_topline)
451 wp->w_topline = wp->w_cursor.lnum; 451 wp->w_topline = wp->w_cursor.lnum;
452 else if (wp->w_cursor.lnum >= wp->w_botline) 452 else if (wp->w_cursor.lnum >= wp->w_botline)
453 wp->w_topline = wp->w_cursor.lnum - wp->w_height + 1; 453 wp->w_topline = wp->w_cursor.lnum - wp->w_height + 1;
454
455 // Don't use "firstline" now.
456 wp->w_firstline = 0;
457 }
458
459 /*
460 * Get the sign group name for window "wp".
461 * Returns a pointer to a static buffer, overwritten on the next call.
462 */
463 static char_u *
464 popup_get_sign_name(win_T *wp)
465 {
466 static char buf[30];
467
468 vim_snprintf(buf, sizeof(buf), "popup-%d", wp->w_id);
469 return (char_u *)buf;
454 } 470 }
455 471
456 /* 472 /*
457 * Highlight the line with the cursor. 473 * Highlight the line with the cursor.
458 * Also scrolls the text to put the cursor line in view. 474 * Also scrolls the text to put the cursor line in view.
459 */ 475 */
460 static void 476 static void
461 popup_highlight_curline(win_T *wp) 477 popup_highlight_curline(win_T *wp)
462 { 478 {
463 int id; 479 int sign_id = 0;
464 char buf[100]; 480 char_u *sign_name = popup_get_sign_name(wp);
465 481
466 match_delete(wp, 1, FALSE); 482 buf_delete_signs(wp->w_buffer, (char_u *)"popupmenu");
467 483
468 if ((wp->w_popup_flags & POPF_CURSORLINE) != 0) 484 if ((wp->w_popup_flags & POPF_CURSORLINE) != 0)
469 { 485 {
470 popup_show_curline(wp); 486 popup_show_curline(wp);
471 487
472 id = syn_name2id((char_u *)"PopupSelected"); 488 if (!sign_exists_by_name(sign_name))
473 vim_snprintf(buf, sizeof(buf), "\\%%%dl.*", (int)wp->w_cursor.lnum); 489 {
474 match_add(wp, (char_u *)(id == 0 ? "PmenuSel" : "PopupSelected"), 490 char *linehl = "PopupSelected";
475 (char_u *)buf, 10, 1, NULL, NULL); 491
476 } 492 if (syn_name2id((char_u *)linehl) == 0)
493 linehl = "PmenuSel";
494 sign_define_by_name(sign_name, NULL,
495 (char_u *)linehl, NULL, NULL);
496 }
497
498 sign_place(&sign_id, (char_u *)"popupmenu", sign_name,
499 wp->w_buffer, wp->w_cursor.lnum, SIGN_DEF_PRIO);
500 redraw_win_later(wp, NOT_VALID);
501 }
502 else
503 sign_undefine_by_name(sign_name, FALSE);
477 } 504 }
478 505
479 /* 506 /*
480 * Shared between popup_create() and f_popup_setoptions(). 507 * Shared between popup_create() and f_popup_setoptions().
481 */ 508 */
543 str = dict_get_string(dict, (char_u *)"highlight", FALSE); 570 str = dict_get_string(dict, (char_u *)"highlight", FALSE);
544 if (str != NULL) 571 if (str != NULL)
545 set_string_option_direct_in_win(wp, (char_u *)"wincolor", -1, 572 set_string_option_direct_in_win(wp, (char_u *)"wincolor", -1,
546 str, OPT_FREE|OPT_LOCAL, 0); 573 str, OPT_FREE|OPT_LOCAL, 0);
547 574
575 set_string_option_direct_in_win(wp, (char_u *)"signcolumn", -1,
576 (char_u *)"no", OPT_FREE|OPT_LOCAL, 0);
548 set_padding_border(dict, wp->w_popup_padding, "padding", 999); 577 set_padding_border(dict, wp->w_popup_padding, "padding", 999);
549 set_padding_border(dict, wp->w_popup_border, "border", 1); 578 set_padding_border(dict, wp->w_popup_border, "border", 1);
550 579
551 di = dict_find(dict, (char_u *)"borderhighlight", -1); 580 di = dict_find(dict, (char_u *)"borderhighlight", -1);
552 if (di != NULL) 581 if (di != NULL)
1217 int nr; 1246 int nr;
1218 int i; 1247 int i;
1219 1248
1220 if (argvars != NULL) 1249 if (argvars != NULL)
1221 { 1250 {
1222 // Check arguments look OK. 1251 // Check that arguments look OK.
1223 if (argvars[0].v_type == VAR_NUMBER) 1252 if (argvars[0].v_type == VAR_NUMBER)
1224 { 1253 {
1225 buf = buflist_findnr( argvars[0].vval.v_number); 1254 buf = buflist_findnr( argvars[0].vval.v_number);
1226 if (buf == NULL) 1255 if (buf == NULL)
1227 { 1256 {
1669 if ((c == 'j' || c == 'J' || c == K_DOWN) 1698 if ((c == 'j' || c == 'J' || c == K_DOWN)
1670 && wp->w_cursor.lnum < wp->w_buffer->b_ml.ml_line_count) 1699 && wp->w_cursor.lnum < wp->w_buffer->b_ml.ml_line_count)
1671 ++wp->w_cursor.lnum; 1700 ++wp->w_cursor.lnum;
1672 if (old_lnum != wp->w_cursor.lnum) 1701 if (old_lnum != wp->w_cursor.lnum)
1673 { 1702 {
1674 popup_highlight_curline(wp); 1703 // caller will call popup_highlight_curline()
1675 return; 1704 return;
1676 } 1705 }
1677 1706
1678 if (c == 'x' || c == 'X' || c == ESC || c == Ctrl_C) 1707 if (c == 'x' || c == 'X' || c == ESC || c == Ctrl_C)
1679 { 1708 {
1847 } 1876 }
1848 1877
1849 static void 1878 static void
1850 popup_free(win_T *wp) 1879 popup_free(win_T *wp)
1851 { 1880 {
1881 sign_undefine_by_name(popup_get_sign_name(wp), FALSE);
1852 wp->w_buffer->b_locked = FALSE; 1882 wp->w_buffer->b_locked = FALSE;
1853 if (wp->w_winrow + wp->w_height >= cmdline_row) 1883 if (wp->w_winrow + wp->w_height >= cmdline_row)
1854 clear_cmdline = TRUE; 1884 clear_cmdline = TRUE;
1855 win_free_popup(wp); 1885 win_free_popup(wp);
1886
1856 redraw_all_later(NOT_VALID); 1887 redraw_all_later(NOT_VALID);
1857 popup_mask_refresh = TRUE; 1888 popup_mask_refresh = TRUE;
1858 } 1889 }
1859 1890
1860 /* 1891 /*
2159 dict_add_number(dict, "zindex", wp->w_zindex); 2190 dict_add_number(dict, "zindex", wp->w_zindex);
2160 dict_add_number(dict, "fixed", wp->w_popup_fixed); 2191 dict_add_number(dict, "fixed", wp->w_popup_fixed);
2161 dict_add_string(dict, "title", wp->w_popup_title); 2192 dict_add_string(dict, "title", wp->w_popup_title);
2162 dict_add_number(dict, "wrap", wp->w_p_wrap); 2193 dict_add_number(dict, "wrap", wp->w_p_wrap);
2163 dict_add_number(dict, "drag", wp->w_popup_drag); 2194 dict_add_number(dict, "drag", wp->w_popup_drag);
2164 dict_add_number(dict, "cursorline", (wp->w_popup_flags & POPF_CURSORLINE) != 0); 2195 dict_add_number(dict, "cursorline",
2196 (wp->w_popup_flags & POPF_CURSORLINE) != 0);
2165 dict_add_string(dict, "highlight", wp->w_p_wcr); 2197 dict_add_string(dict, "highlight", wp->w_p_wcr);
2166 if (wp->w_scrollbar_highlight != NULL) 2198 if (wp->w_scrollbar_highlight != NULL)
2167 dict_add_string(dict, "scrollbarhighlight", 2199 dict_add_string(dict, "scrollbarhighlight",
2168 wp->w_scrollbar_highlight); 2200 wp->w_scrollbar_highlight);
2169 if (wp->w_thumb_highlight != NULL) 2201 if (wp->w_thumb_highlight != NULL)
2319 argv[2].v_type = VAR_UNKNOWN; 2351 argv[2].v_type = VAR_UNKNOWN;
2320 2352
2321 // NOTE: The callback might close the popup, thus make "wp" invalid. 2353 // NOTE: The callback might close the popup, thus make "wp" invalid.
2322 call_callback(&wp->w_filter_cb, -1, 2354 call_callback(&wp->w_filter_cb, -1,
2323 &rettv, 2, argv, NULL, 0L, 0L, &dummy, TRUE, NULL); 2355 &rettv, 2, argv, NULL, 0L, 0L, &dummy, TRUE, NULL);
2324 if (old_lnum != wp->w_cursor.lnum) 2356 if (win_valid_popup(wp) && old_lnum != wp->w_cursor.lnum)
2325 popup_highlight_curline(wp); 2357 popup_highlight_curline(wp);
2326 2358
2327 res = tv_get_number(&rettv); 2359 res = tv_get_number(&rettv);
2328 vim_free(argv[1].vval.v_string); 2360 vim_free(argv[1].vval.v_string);
2329 clear_tv(&rettv); 2361 clear_tv(&rettv);