mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 8.1.1659: popup window "mousemoved" values not correct
Problem: Popup window "mousemoved" values not correct. Solution: Convert text column to mouse column.
This commit is contained in:
@@ -192,7 +192,7 @@ popup_beval({what}, {options}) *popup_beval()*
|
|||||||
let pos = screenpos(v:beval_winnr, v:beval_lnum, v:beval_col)
|
let pos = screenpos(v:beval_winnr, v:beval_lnum, v:beval_col)
|
||||||
call popup_create({what}, {
|
call popup_create({what}, {
|
||||||
\ 'pos': 'botleft',
|
\ 'pos': 'botleft',
|
||||||
\ 'line': pos.lnum - 1,
|
\ 'line': pos.row - 1,
|
||||||
\ 'col': pos.col,
|
\ 'col': pos.col,
|
||||||
\ 'mousemoved': 'WORD',
|
\ 'mousemoved': 'WORD',
|
||||||
\ })
|
\ })
|
||||||
@@ -762,38 +762,49 @@ Example for using a popup window for 'ballooneval': >
|
|||||||
set ballooneval balloonevalterm
|
set ballooneval balloonevalterm
|
||||||
set balloonexpr=BalloonExpr()
|
set balloonexpr=BalloonExpr()
|
||||||
let s:winid = 0
|
let s:winid = 0
|
||||||
|
let s:last_text = ''
|
||||||
|
|
||||||
func BalloonExpr()
|
func BalloonExpr()
|
||||||
if s:winid
|
if s:winid && popup_getpos(s:winid) != {}
|
||||||
call popup_close(s:winid)
|
" previous popup window still shows
|
||||||
let s:winid = 0
|
if v:beval_text == s:last_text
|
||||||
|
" Still the same text, keep the existing popup
|
||||||
|
return ''
|
||||||
endif
|
endif
|
||||||
let s:winid = popup_beval([bufname(v:beval_bufnr), v:beval_text], {})
|
call popup_close(s:winid)
|
||||||
|
endif
|
||||||
|
let s:winid = popup_beval(v:beval_text, {'mousemoved': 'word'})
|
||||||
|
let s:last_text = v:beval_text
|
||||||
return ''
|
return ''
|
||||||
endfunc
|
endfunc
|
||||||
<
|
<
|
||||||
If the text has to be obtained asynchronously return an empty string from the
|
If the text has to be obtained asynchronously return an empty string from the
|
||||||
expression function and call popup_beval() once the text is available. In
|
expression function and call popup_beval() once the text is available. In
|
||||||
this example similated with a timer callback: >
|
this example simulated with a timer callback: >
|
||||||
|
|
||||||
set ballooneval balloonevalterm
|
set ballooneval balloonevalterm
|
||||||
set balloonexpr=BalloonExpr()
|
set balloonexpr=BalloonExpr()
|
||||||
let s:winid = 0
|
let s:winid = 0
|
||||||
|
let s:balloonText = ''
|
||||||
|
|
||||||
func BalloonExpr()
|
func BalloonExpr()
|
||||||
if s:winid
|
if s:winid && popup_getpos(s:winid) != {}
|
||||||
|
" previous popup window still shows
|
||||||
|
if v:beval_text == s:balloonText
|
||||||
|
" Still the same text, keep the existing popup
|
||||||
|
return ''
|
||||||
|
endif
|
||||||
call popup_close(s:winid)
|
call popup_close(s:winid)
|
||||||
let s:winid = 0
|
let s:winid = 0
|
||||||
endif
|
endif
|
||||||
" simulate an asynchronous loopup for the text to display
|
" simulate an asynchronous loopup for the text to display
|
||||||
let s:balloonFile = bufname(v:beval_bufnr)
|
let s:balloonText = v:beval_text
|
||||||
let s:balloonWord = v:beval_text
|
|
||||||
call timer_start(100, 'ShowPopup')
|
call timer_start(100, 'ShowPopup')
|
||||||
return ''
|
return ''
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
func ShowPopup(id)
|
func ShowPopup(id)
|
||||||
let s:winid = popup_beval([s:balloonFile, s:balloonWord], {})
|
let s:winid = popup_beval(s:balloonText, {'mousemoved': 'word'})
|
||||||
endfunc
|
endfunc
|
||||||
<
|
<
|
||||||
|
|
||||||
|
@@ -184,14 +184,24 @@ set_mousemoved_values(win_T *wp)
|
|||||||
static void
|
static void
|
||||||
set_mousemoved_columns(win_T *wp, int flags)
|
set_mousemoved_columns(win_T *wp, int flags)
|
||||||
{
|
{
|
||||||
|
win_T *textwp;
|
||||||
char_u *text;
|
char_u *text;
|
||||||
int col;
|
int col;
|
||||||
|
pos_T pos;
|
||||||
|
colnr_T mcol;
|
||||||
|
|
||||||
if (find_word_under_cursor(mouse_row, mouse_col, TRUE, flags,
|
if (find_word_under_cursor(mouse_row, mouse_col, TRUE, flags,
|
||||||
NULL, NULL, &text, NULL, &col) == OK)
|
&textwp, &pos.lnum, &text, NULL, &col) == OK)
|
||||||
{
|
{
|
||||||
wp->w_popup_mouse_mincol = col;
|
// convert text column to mouse column
|
||||||
wp->w_popup_mouse_maxcol = col + STRLEN(text) - 1;
|
pos.col = col;
|
||||||
|
pos.coladd = 0;
|
||||||
|
getvcol(textwp, &pos, &mcol, NULL, NULL);
|
||||||
|
wp->w_popup_mouse_mincol = mcol;
|
||||||
|
|
||||||
|
pos.col = col + STRLEN(text) - 1;
|
||||||
|
getvcol(textwp, &pos, NULL, NULL, &mcol);
|
||||||
|
wp->w_popup_mouse_maxcol = mcol;
|
||||||
vim_free(text);
|
vim_free(text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -777,6 +777,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1659,
|
||||||
/**/
|
/**/
|
||||||
1658,
|
1658,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user