]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
patch 9.2.0744: popup_atcursor() closes immediately on white space v9.2.0744
authorYasuhiro Matsumoto <mattn.jp@gmail.com>
Sun, 28 Jun 2026 18:43:03 +0000 (18:43 +0000)
committerChristian Brabandt <cb@256bit.org>
Sun, 28 Jun 2026 18:43:03 +0000 (18:43 +0000)
Problem:  popup_atcursor() closes immediately on white space (Mao-Yining)
Solution: Set w_popup_mincol and w_popup_maxcol to the cursor column
          (Yasuhiro Matsumoto)

When the cursor is on white space find_ident_under_cursor() skips forward
to the next word, so the moved range did not cover the cursor column and
popup_check_cursor_pos() closed the popup right away.  Keep the cursor
column in that case.

fixes:  #20652
closes: #20659

Signed-off-by: Yasuhiro Matsumoto <mattn.jp@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
src/popupwin.c
src/testdir/test_popupwin.vim
src/version.c

index a497ea58cab9fd73f5819293d5101e360f61560c..d30cc33e17ff23e1a8eaed02d2349df81c2b02b5 100644 (file)
@@ -233,12 +233,25 @@ set_moved_columns(win_T *wp, int flags)
 {
     char_u     *ptr;
     int                len = find_ident_under_cursor(&ptr, flags | FIND_NOERROR);
+    int                mincol;
 
     if (len <= 0)
        return;
 
-    wp->w_popup_mincol = (int)(ptr - ml_get_curline());
-    wp->w_popup_maxcol = wp->w_popup_mincol + len - 1;
+    // When the cursor is on white space find_ident_under_cursor() skips
+    // forward to the next word, whose range does not cover the cursor column.
+    // Keep the cursor column then, otherwise popup_check_cursor_pos() would
+    // close the popup right away.
+    mincol = (int)(ptr - ml_get_curline());
+    if (curwin->w_cursor.col < mincol)
+    {
+       wp->w_popup_mincol = curwin->w_cursor.col;
+       wp->w_popup_maxcol = curwin->w_cursor.col;
+       return;
+    }
+
+    wp->w_popup_mincol = mincol;
+    wp->w_popup_maxcol = mincol + len - 1;
 }
 
 /*
index 5156584e4ffed04619caa102289470da51bf8152..7e8fb6233d09f712219453fea5e04532003467fe 100644 (file)
@@ -2331,6 +2331,20 @@ func Test_popup_moved()
   call assert_equal({}, popup_getpos(winid))
   call popup_clear()
 
+  " On white space find_ident_under_cursor() skips forward to the next word,
+  " whose range does not cover the cursor.  The cursor column must be used so
+  " the popup is not closed right away.
+  exe "normal gg4|"
+  let winid = popup_atcursor('text', {})
+  redraw
+  call assert_equal(1, popup_getpos(winid).visible)
+  call assert_equal([1, 3, 3], popup_getoptions(winid).moved)
+  call feedkeys("i\<Esc>", 'xt')
+  call assert_equal(1, popup_getpos(winid).visible)
+  call feedkeys("$i\<Esc>", 'xt')
+  call assert_equal({}, popup_getpos(winid))
+  call popup_clear()
+
   bwipe!
   call test_override('ALL', 0)
 endfunc
index b76dd5b23b6ac761c7accead84f0b571e6d1f0eb..6509e93096a2850ece1fa0ea0599d25ac1cf52c3 100644 (file)
@@ -759,6 +759,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    744,
 /**/
     743,
 /**/