Skip to content

Commit b05caa7

Browse files
committed
patch 8.1.1659: popup window "mousemoved" values not correct
Problem: Popup window "mousemoved" values not correct. Solution: Convert text column to mouse column.
1 parent 3b849af commit b05caa7

3 files changed

Lines changed: 35 additions & 12 deletions

File tree

runtime/doc/popup.txt

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ popup_beval({what}, {options}) *popup_beval()*
192192
let pos = screenpos(v:beval_winnr, v:beval_lnum, v:beval_col)
193193
call popup_create({what}, {
194194
\ 'pos': 'botleft',
195-
\ 'line': pos.lnum - 1,
195+
\ 'line': pos.row - 1,
196196
\ 'col': pos.col,
197197
\ 'mousemoved': 'WORD',
198198
\ })
@@ -762,38 +762,49 @@ Example for using a popup window for 'ballooneval': >
762762
set ballooneval balloonevalterm
763763
set balloonexpr=BalloonExpr()
764764
let s:winid = 0
765+
let s:last_text = ''
765766
766767
func BalloonExpr()
767-
if s:winid
768+
if s:winid && popup_getpos(s:winid) != {}
769+
" previous popup window still shows
770+
if v:beval_text == s:last_text
771+
" Still the same text, keep the existing popup
772+
return ''
773+
endif
768774
call popup_close(s:winid)
769-
let s:winid = 0
770775
endif
771-
let s:winid = popup_beval([bufname(v:beval_bufnr), v:beval_text], {})
776+
let s:winid = popup_beval(v:beval_text, {'mousemoved': 'word'})
777+
let s:last_text = v:beval_text
772778
return ''
773779
endfunc
774780
<
775781
If the text has to be obtained asynchronously return an empty string from the
776782
expression function and call popup_beval() once the text is available. In
777-
this example similated with a timer callback: >
783+
this example simulated with a timer callback: >
778784
779785
set ballooneval balloonevalterm
780786
set balloonexpr=BalloonExpr()
781787
let s:winid = 0
788+
let s:balloonText = ''
782789
783790
func BalloonExpr()
784-
if s:winid
791+
if s:winid && popup_getpos(s:winid) != {}
792+
" previous popup window still shows
793+
if v:beval_text == s:balloonText
794+
" Still the same text, keep the existing popup
795+
return ''
796+
endif
785797
call popup_close(s:winid)
786798
let s:winid = 0
787799
endif
788800
" simulate an asynchronous loopup for the text to display
789-
let s:balloonFile = bufname(v:beval_bufnr)
790-
let s:balloonWord = v:beval_text
801+
let s:balloonText = v:beval_text
791802
call timer_start(100, 'ShowPopup')
792803
return ''
793804
endfunc
794805
795806
func ShowPopup(id)
796-
let s:winid = popup_beval([s:balloonFile, s:balloonWord], {})
807+
let s:winid = popup_beval(s:balloonText, {'mousemoved': 'word'})
797808
endfunc
798809
<
799810

src/popupwin.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,24 @@ set_mousemoved_values(win_T *wp)
184184
static void
185185
set_mousemoved_columns(win_T *wp, int flags)
186186
{
187+
win_T *textwp;
187188
char_u *text;
188189
int col;
190+
pos_T pos;
191+
colnr_T mcol;
189192

190193
if (find_word_under_cursor(mouse_row, mouse_col, TRUE, flags,
191-
NULL, NULL, &text, NULL, &col) == OK)
194+
&textwp, &pos.lnum, &text, NULL, &col) == OK)
192195
{
193-
wp->w_popup_mouse_mincol = col;
194-
wp->w_popup_mouse_maxcol = col + STRLEN(text) - 1;
196+
// convert text column to mouse column
197+
pos.col = col;
198+
pos.coladd = 0;
199+
getvcol(textwp, &pos, &mcol, NULL, NULL);
200+
wp->w_popup_mouse_mincol = mcol;
201+
202+
pos.col = col + STRLEN(text) - 1;
203+
getvcol(textwp, &pos, NULL, NULL, &mcol);
204+
wp->w_popup_mouse_maxcol = mcol;
195205
vim_free(text);
196206
}
197207
}

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,8 @@ static char *(features[]) =
777777

778778
static int included_patches[] =
779779
{ /* Add new patch number below this line */
780+
/**/
781+
1659,
780782
/**/
781783
1658,
782784
/**/

0 commit comments

Comments
 (0)