Mercurial > vim
comparison src/popupwin.c @ 17429:6e756ad5ef1a v8.1.1713
patch 8.1.1713: highlighting cursor line only works with popup_menu()
commit https://github.com/vim/vim/commit/df9c6cad8cc318e26e99c3b055f0788e7d6582de
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Jul 18 13:46:42 2019 +0200
patch 8.1.1713: highlighting cursor line only works with popup_menu()
Problem: Highlighting cursor line only works with popup_menu().
Solution: Add the "cursorline" property. (Naruhiko Nishino, closes https://github.com/vim/vim/issues/4671)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 18 Jul 2019 14:00:08 +0200 |
parents | 73e81cd9e6cb |
children | ce35cdbe9f74 |
comparison
equal
deleted
inserted
replaced
17428:30036b80e5ca | 17429:6e756ad5ef1a |
---|---|
436 { | 436 { |
437 str = tv_get_string(&di->di_tv); | 437 str = tv_get_string(&di->di_tv); |
438 if (*str != NUL) | 438 if (*str != NUL) |
439 *pval = vim_strsave(str); | 439 *pval = vim_strsave(str); |
440 } | 440 } |
441 } | |
442 } | |
443 | |
444 /* | |
445 * Highlight the line with the cursor. | |
446 * Also scrolls the text to put the cursor line in view. | |
447 */ | |
448 static void | |
449 popup_highlight_curline(win_T *wp) | |
450 { | |
451 int id; | |
452 char buf[100]; | |
453 | |
454 match_delete(wp, 1, FALSE); | |
455 | |
456 if ((wp->w_popup_flags & POPF_CURSORLINE) != 0) | |
457 { | |
458 // Scroll to show the line with the cursor. This assumes lines don't | |
459 // wrap. | |
460 while (wp->w_topline + wp->w_height - 1 < wp->w_cursor.lnum) | |
461 wp->w_topline++; | |
462 while (wp->w_cursor.lnum < wp->w_topline) | |
463 wp->w_topline--; | |
464 | |
465 id = syn_name2id((char_u *)"PopupSelected"); | |
466 vim_snprintf(buf, sizeof(buf), "\\%%%dl.*", (int)wp->w_cursor.lnum); | |
467 match_add(wp, (char_u *)(id == 0 ? "PmenuSel" : "PopupSelected"), | |
468 (char_u *)buf, 10, 1, NULL, NULL); | |
441 } | 469 } |
442 } | 470 } |
443 | 471 |
444 /* | 472 /* |
445 * Shared between popup_create() and f_popup_setoptions(). | 473 * Shared between popup_create() and f_popup_setoptions(). |
633 { | 661 { |
634 set_mousemoved_values(wp); | 662 set_mousemoved_values(wp); |
635 handle_moved_argument(wp, di, TRUE); | 663 handle_moved_argument(wp, di, TRUE); |
636 } | 664 } |
637 | 665 |
666 di = dict_find(dict, (char_u *)"cursorline", -1); | |
667 if (di != NULL) | |
668 { | |
669 if (di->di_tv.v_type == VAR_NUMBER) | |
670 { | |
671 if (di->di_tv.vval.v_number != 0) | |
672 wp->w_popup_flags |= POPF_CURSORLINE; | |
673 else | |
674 wp->w_popup_flags &= ~POPF_CURSORLINE; | |
675 } | |
676 else | |
677 semsg(_(e_invargval), "cursorline"); | |
678 } | |
679 | |
638 di = dict_find(dict, (char_u *)"filter", -1); | 680 di = dict_find(dict, (char_u *)"filter", -1); |
639 if (di != NULL) | 681 if (di != NULL) |
640 { | 682 { |
641 callback_T callback = get_callback(&di->di_tv); | 683 callback_T callback = get_callback(&di->di_tv); |
642 | 684 |
660 } | 702 } |
661 } | 703 } |
662 | 704 |
663 /* | 705 /* |
664 * Go through the options in "dict" and apply them to popup window "wp". | 706 * Go through the options in "dict" and apply them to popup window "wp". |
707 * Only used when creating a new popup window. | |
665 */ | 708 */ |
666 static void | 709 static void |
667 apply_options(win_T *wp, dict_T *dict) | 710 apply_options(win_T *wp, dict_T *dict) |
668 { | 711 { |
669 int nr; | 712 int nr; |
677 wp->w_popup_flags |= POPF_HIDDEN; | 720 wp->w_popup_flags |= POPF_HIDDEN; |
678 --wp->w_buffer->b_nwindows; | 721 --wp->w_buffer->b_nwindows; |
679 } | 722 } |
680 | 723 |
681 popup_mask_refresh = TRUE; | 724 popup_mask_refresh = TRUE; |
725 popup_highlight_curline(wp); | |
682 } | 726 } |
683 | 727 |
684 /* | 728 /* |
685 * Add lines to the popup from a list of strings. | 729 * Add lines to the popup from a list of strings. |
686 */ | 730 */ |
1311 callback = get_callback(&tv); | 1355 callback = get_callback(&tv); |
1312 if (callback.cb_name != NULL) | 1356 if (callback.cb_name != NULL) |
1313 set_callback(&wp->w_filter_cb, &callback); | 1357 set_callback(&wp->w_filter_cb, &callback); |
1314 | 1358 |
1315 wp->w_p_wrap = 0; | 1359 wp->w_p_wrap = 0; |
1360 wp->w_popup_flags |= POPF_CURSORLINE; | |
1316 } | 1361 } |
1317 | 1362 |
1318 for (i = 0; i < 4; ++i) | 1363 for (i = 0; i < 4; ++i) |
1319 VIM_CLEAR(wp->w_border_highlight[i]); | 1364 VIM_CLEAR(wp->w_border_highlight[i]); |
1320 for (i = 0; i < 8; ++i) | 1365 for (i = 0; i < 8; ++i) |
1500 || wp == mouse_find_win(&row, &col, FIND_POPUP))) | 1545 || wp == mouse_find_win(&row, &col, FIND_POPUP))) |
1501 // do not consume the key, allow for dragging the popup | 1546 // do not consume the key, allow for dragging the popup |
1502 rettv->vval.v_number = 0; | 1547 rettv->vval.v_number = 0; |
1503 } | 1548 } |
1504 | 1549 |
1505 static void | |
1506 popup_highlight_curline(win_T *wp) | |
1507 { | |
1508 int id; | |
1509 char buf[100]; | |
1510 | |
1511 match_delete(wp, 1, FALSE); | |
1512 | |
1513 // Scroll to show the line with the cursor. This assumes lines don't wrap. | |
1514 while (wp->w_topline + wp->w_height - 1 < wp->w_cursor.lnum) | |
1515 wp->w_topline++; | |
1516 while (wp->w_cursor.lnum < wp->w_topline) | |
1517 wp->w_topline--; | |
1518 | |
1519 id = syn_name2id((char_u *)"PopupSelected"); | |
1520 vim_snprintf(buf, sizeof(buf), "\\%%%dl.*", (int)wp->w_cursor.lnum); | |
1521 match_add(wp, (char_u *)(id == 0 ? "PmenuSel" : "PopupSelected"), | |
1522 (char_u *)buf, 10, 1, NULL, NULL); | |
1523 } | |
1524 | |
1525 /* | 1550 /* |
1526 * popup_filter_menu({text}, {options}) | 1551 * popup_filter_menu({text}, {options}) |
1527 */ | 1552 */ |
1528 void | 1553 void |
1529 f_popup_filter_menu(typval_T *argvars, typval_T *rettv) | 1554 f_popup_filter_menu(typval_T *argvars, typval_T *rettv) |
1628 * popup_menu({text}, {options}) | 1653 * popup_menu({text}, {options}) |
1629 */ | 1654 */ |
1630 void | 1655 void |
1631 f_popup_menu(typval_T *argvars, typval_T *rettv) | 1656 f_popup_menu(typval_T *argvars, typval_T *rettv) |
1632 { | 1657 { |
1633 win_T *wp = popup_create(argvars, rettv, TYPE_MENU); | 1658 popup_create(argvars, rettv, TYPE_MENU); |
1634 | |
1635 if (wp != NULL) | |
1636 popup_highlight_curline(wp); | |
1637 } | 1659 } |
1638 | 1660 |
1639 /* | 1661 /* |
1640 * popup_notification({text}, {options}) | 1662 * popup_notification({text}, {options}) |
1641 */ | 1663 */ |
1856 apply_general_options(wp, dict); | 1878 apply_general_options(wp, dict); |
1857 | 1879 |
1858 if (old_firstline != wp->w_firstline) | 1880 if (old_firstline != wp->w_firstline) |
1859 redraw_win_later(wp, NOT_VALID); | 1881 redraw_win_later(wp, NOT_VALID); |
1860 popup_mask_refresh = TRUE; | 1882 popup_mask_refresh = TRUE; |
1883 popup_highlight_curline(wp); | |
1861 popup_adjust_position(wp); | 1884 popup_adjust_position(wp); |
1862 } | 1885 } |
1863 | 1886 |
1864 /* | 1887 /* |
1865 * popup_getpos({id}) | 1888 * popup_getpos({id}) |
2045 dict_add_number(dict, "zindex", wp->w_zindex); | 2068 dict_add_number(dict, "zindex", wp->w_zindex); |
2046 dict_add_number(dict, "fixed", wp->w_popup_fixed); | 2069 dict_add_number(dict, "fixed", wp->w_popup_fixed); |
2047 dict_add_string(dict, "title", wp->w_popup_title); | 2070 dict_add_string(dict, "title", wp->w_popup_title); |
2048 dict_add_number(dict, "wrap", wp->w_p_wrap); | 2071 dict_add_number(dict, "wrap", wp->w_p_wrap); |
2049 dict_add_number(dict, "drag", wp->w_popup_drag); | 2072 dict_add_number(dict, "drag", wp->w_popup_drag); |
2073 dict_add_number(dict, "cursorline", (wp->w_popup_flags & POPF_CURSORLINE) != 0); | |
2050 dict_add_string(dict, "highlight", wp->w_p_wcr); | 2074 dict_add_string(dict, "highlight", wp->w_p_wcr); |
2051 if (wp->w_scrollbar_highlight != NULL) | 2075 if (wp->w_scrollbar_highlight != NULL) |
2052 dict_add_string(dict, "scrollbarhighlight", | 2076 dict_add_string(dict, "scrollbarhighlight", |
2053 wp->w_scrollbar_highlight); | 2077 wp->w_scrollbar_highlight); |
2054 if (wp->w_thumb_highlight != NULL) | 2078 if (wp->w_thumb_highlight != NULL) |
2179 int res; | 2203 int res; |
2180 typval_T rettv; | 2204 typval_T rettv; |
2181 int dummy; | 2205 int dummy; |
2182 typval_T argv[3]; | 2206 typval_T argv[3]; |
2183 char_u buf[NUMBUFLEN]; | 2207 char_u buf[NUMBUFLEN]; |
2208 linenr_T old_lnum = wp->w_cursor.lnum; | |
2184 | 2209 |
2185 // Emergency exit: CTRL-C closes the popup. | 2210 // Emergency exit: CTRL-C closes the popup. |
2186 if (c == Ctrl_C) | 2211 if (c == Ctrl_C) |
2187 { | 2212 { |
2188 rettv.v_type = VAR_NUMBER; | 2213 rettv.v_type = VAR_NUMBER; |
2203 argv[2].v_type = VAR_UNKNOWN; | 2228 argv[2].v_type = VAR_UNKNOWN; |
2204 | 2229 |
2205 // NOTE: The callback might close the popup, thus make "wp" invalid. | 2230 // NOTE: The callback might close the popup, thus make "wp" invalid. |
2206 call_callback(&wp->w_filter_cb, -1, | 2231 call_callback(&wp->w_filter_cb, -1, |
2207 &rettv, 2, argv, NULL, 0L, 0L, &dummy, TRUE, NULL); | 2232 &rettv, 2, argv, NULL, 0L, 0L, &dummy, TRUE, NULL); |
2233 if (old_lnum != wp->w_cursor.lnum) | |
2234 popup_highlight_curline(wp); | |
2235 | |
2208 res = tv_get_number(&rettv); | 2236 res = tv_get_number(&rettv); |
2209 vim_free(argv[1].vval.v_string); | 2237 vim_free(argv[1].vval.v_string); |
2210 clear_tv(&rettv); | 2238 clear_tv(&rettv); |
2211 return res; | 2239 return res; |
2212 } | 2240 } |