patch 8.1.1678: using popup_menu() does not scroll to show the selected line
Problem: When using popup_menu() does not scroll to show the selected line.
Solution: Scroll the text. (Naruhiko Nishino, closes #4651)
diff --git a/src/popupwin.c b/src/popupwin.c
index 3185686..c6c5910 100644
--- a/src/popupwin.c
+++ b/src/popupwin.c
@@ -1512,6 +1512,12 @@
match_delete(wp, 1, FALSE);
+ // Scroll to show the line with the cursor. This assumes lines don't wrap.
+ while (wp->w_topline + wp->w_height - 1 < wp->w_cursor.lnum)
+ wp->w_topline++;
+ while (wp->w_cursor.lnum < wp->w_topline)
+ wp->w_topline--;
+
id = syn_name2id((char_u *)"PopupSelected");
vim_snprintf(buf, sizeof(buf), "\\%%%dl.*", (int)wp->w_cursor.lnum);
match_add(wp, (char_u *)(id == 0 ? "PmenuSel" : "PopupSelected"),