diff src/popupwin.c @ 17358:d1ea88736ebd v8.1.1678

patch 8.1.1678: using popup_menu() does not scroll to show the selected line commit https://github.com/vim/vim/commit/a901a37bae9f4e2848d6d7ac7b0875d72f43e1eb Author: Bram Moolenaar <Bram@vim.org> Date: Sat Jul 13 16:38:50 2019 +0200 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 https://github.com/vim/vim/issues/4651)
author Bram Moolenaar <Bram@vim.org>
date Sat, 13 Jul 2019 16:45:04 +0200
parents 102ed3a26a5d
children b18fd36fdf46
line wrap: on
line diff
--- a/src/popupwin.c
+++ b/src/popupwin.c
@@ -1512,6 +1512,12 @@ popup_highlight_curline(win_T *wp)
 
     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"),