@@ -441,6 +441,34 @@ check_highlight(dict_T *dict, char *name, char_u **pval)
441441 }
442442}
443443
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 );
469+ }
470+ }
471+
444472/*
445473 * Shared between popup_create() and f_popup_setoptions().
446474 */
@@ -635,6 +663,20 @@ apply_general_options(win_T *wp, dict_T *dict)
635663 handle_moved_argument (wp , di , TRUE);
636664 }
637665
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+
638680 di = dict_find (dict , (char_u * )"filter" , -1 );
639681 if (di != NULL )
640682 {
@@ -662,6 +704,7 @@ apply_general_options(win_T *wp, dict_T *dict)
662704
663705/*
664706 * Go through the options in "dict" and apply them to popup window "wp".
707+ * Only used when creating a new popup window.
665708 */
666709 static void
667710apply_options (win_T * wp , dict_T * dict )
@@ -679,6 +722,7 @@ apply_options(win_T *wp, dict_T *dict)
679722 }
680723
681724 popup_mask_refresh = TRUE;
725+ popup_highlight_curline (wp );
682726}
683727
684728/*
@@ -1313,6 +1357,7 @@ popup_create(typval_T *argvars, typval_T *rettv, create_type_T type)
13131357 set_callback (& wp -> w_filter_cb , & callback );
13141358
13151359 wp -> w_p_wrap = 0 ;
1360+ wp -> w_popup_flags |= POPF_CURSORLINE ;
13161361 }
13171362
13181363 for (i = 0 ; i < 4 ; ++ i )
@@ -1502,26 +1547,6 @@ filter_handle_drag(win_T *wp, int c, typval_T *rettv)
15021547 rettv -> vval .v_number = 0 ;
15031548}
15041549
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-
15251550/*
15261551 * popup_filter_menu({text}, {options})
15271552 */
@@ -1630,10 +1655,7 @@ f_popup_dialog(typval_T *argvars, typval_T *rettv)
16301655 void
16311656f_popup_menu (typval_T * argvars , typval_T * rettv )
16321657{
1633- win_T * wp = popup_create (argvars , rettv , TYPE_MENU );
1634-
1635- if (wp != NULL )
1636- popup_highlight_curline (wp );
1658+ popup_create (argvars , rettv , TYPE_MENU );
16371659}
16381660
16391661/*
@@ -1858,6 +1880,7 @@ f_popup_setoptions(typval_T *argvars, typval_T *rettv UNUSED)
18581880 if (old_firstline != wp -> w_firstline )
18591881 redraw_win_later (wp , NOT_VALID );
18601882 popup_mask_refresh = TRUE;
1883+ popup_highlight_curline (wp );
18611884 popup_adjust_position (wp );
18621885}
18631886
@@ -2047,6 +2070,7 @@ f_popup_getoptions(typval_T *argvars, typval_T *rettv)
20472070 dict_add_string (dict , "title" , wp -> w_popup_title );
20482071 dict_add_number (dict , "wrap" , wp -> w_p_wrap );
20492072 dict_add_number (dict , "drag" , wp -> w_popup_drag );
2073+ dict_add_number (dict , "cursorline" , (wp -> w_popup_flags & POPF_CURSORLINE ) != 0 );
20502074 dict_add_string (dict , "highlight" , wp -> w_p_wcr );
20512075 if (wp -> w_scrollbar_highlight != NULL )
20522076 dict_add_string (dict , "scrollbarhighlight" ,
@@ -2181,6 +2205,7 @@ invoke_popup_filter(win_T *wp, int c)
21812205 int dummy ;
21822206 typval_T argv [3 ];
21832207 char_u buf [NUMBUFLEN ];
2208+ linenr_T old_lnum = wp -> w_cursor .lnum ;
21842209
21852210 // Emergency exit: CTRL-C closes the popup.
21862211 if (c == Ctrl_C )
@@ -2205,6 +2230,9 @@ invoke_popup_filter(win_T *wp, int c)
22052230 // NOTE: The callback might close the popup, thus make "wp" invalid.
22062231 call_callback (& wp -> w_filter_cb , -1 ,
22072232 & rettv , 2 , argv , NULL , 0L , 0L , & dummy , TRUE, NULL );
2233+ if (old_lnum != wp -> w_cursor .lnum )
2234+ popup_highlight_curline (wp );
2235+
22082236 res = tv_get_number (& rettv );
22092237 vim_free (argv [1 ].vval .v_string );
22102238 clear_tv (& rettv );
0 commit comments