mirror of
https://github.com/vim/vim.git
synced 2025-09-26 04:04:07 -04:00
patch 8.1.1751: when redrawing popups plines_win() may be called often
Problem: When redrawing popups plines_win() may be called often. Solution: Pass a cache to mouse_comp_pos().
This commit is contained in:
@@ -43,7 +43,7 @@ find_word_under_cursor(
|
|||||||
{
|
{
|
||||||
// Found a window and the cursor is in the text. Now find the line
|
// Found a window and the cursor is in the text. Now find the line
|
||||||
// number.
|
// number.
|
||||||
if (!mouse_comp_pos(wp, &row, &col, &lnum))
|
if (!mouse_comp_pos(wp, &row, &col, &lnum, NULL))
|
||||||
{
|
{
|
||||||
// Not past end of the file.
|
// Not past end of the file.
|
||||||
lbuf = ml_get_buf(wp->w_buffer, lnum, FALSE);
|
lbuf = ml_get_buf(wp->w_buffer, lnum, FALSE);
|
||||||
|
@@ -4738,7 +4738,7 @@ f_getchar(typval_T *argvars, typval_T *rettv)
|
|||||||
win = mouse_find_win(&row, &col, FIND_POPUP);
|
win = mouse_find_win(&row, &col, FIND_POPUP);
|
||||||
if (win == NULL)
|
if (win == NULL)
|
||||||
return;
|
return;
|
||||||
(void)mouse_comp_pos(win, &row, &col, &lnum);
|
(void)mouse_comp_pos(win, &row, &col, &lnum, NULL);
|
||||||
# ifdef FEAT_TEXT_PROP
|
# ifdef FEAT_TEXT_PROP
|
||||||
if (WIN_IS_POPUP(win))
|
if (WIN_IS_POPUP(win))
|
||||||
winnr = 0;
|
winnr = 0;
|
||||||
|
@@ -2593,6 +2593,10 @@ may_update_popup_mask(int type)
|
|||||||
// Only check which lines are to be updated if not already
|
// Only check which lines are to be updated if not already
|
||||||
// updating all lines.
|
// updating all lines.
|
||||||
if (mask == popup_mask_next)
|
if (mask == popup_mask_next)
|
||||||
|
{
|
||||||
|
int *plines_cache = ALLOC_CLEAR_MULT(int, Rows);
|
||||||
|
win_T *prev_wp = NULL;
|
||||||
|
|
||||||
for (line = 0; line < screen_Rows; ++line)
|
for (line = 0; line < screen_Rows; ++line)
|
||||||
{
|
{
|
||||||
int col_done = 0;
|
int col_done = 0;
|
||||||
@@ -2625,13 +2629,19 @@ may_update_popup_mask(int type)
|
|||||||
wp = mouse_find_win(&line_cp, &col_cp, IGNORE_POPUP);
|
wp = mouse_find_win(&line_cp, &col_cp, IGNORE_POPUP);
|
||||||
if (wp != NULL)
|
if (wp != NULL)
|
||||||
{
|
{
|
||||||
|
if (wp != prev_wp)
|
||||||
|
{
|
||||||
|
vim_memset(plines_cache, 0, sizeof(int) * Rows);
|
||||||
|
prev_wp = wp;
|
||||||
|
}
|
||||||
|
|
||||||
if (line_cp >= wp->w_height)
|
if (line_cp >= wp->w_height)
|
||||||
// In (or below) status line
|
// In (or below) status line
|
||||||
wp->w_redr_status = TRUE;
|
wp->w_redr_status = TRUE;
|
||||||
// compute the position in the buffer line from the
|
// compute the position in the buffer line from the
|
||||||
// position on the screen
|
// position on the screen
|
||||||
else if (mouse_comp_pos(wp, &line_cp, &col_cp,
|
else if (mouse_comp_pos(wp, &line_cp, &col_cp,
|
||||||
&lnum))
|
&lnum, plines_cache))
|
||||||
// past bottom
|
// past bottom
|
||||||
wp->w_redr_status = TRUE;
|
wp->w_redr_status = TRUE;
|
||||||
else
|
else
|
||||||
@@ -2645,6 +2655,9 @@ may_update_popup_mask(int type)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vim_free(plines_cache);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -64,7 +64,7 @@ void clip_x11_set_selection(Clipboard_T *cbd);
|
|||||||
int clip_x11_owner_exists(Clipboard_T *cbd);
|
int clip_x11_owner_exists(Clipboard_T *cbd);
|
||||||
void yank_cut_buffer0(Display *dpy, Clipboard_T *cbd);
|
void yank_cut_buffer0(Display *dpy, Clipboard_T *cbd);
|
||||||
int jump_to_mouse(int flags, int *inclusive, int which_button);
|
int jump_to_mouse(int flags, int *inclusive, int which_button);
|
||||||
int mouse_comp_pos(win_T *win, int *rowp, int *colp, linenr_T *lnump);
|
int mouse_comp_pos(win_T *win, int *rowp, int *colp, linenr_T *lnump, int *plines_cache);
|
||||||
win_T *mouse_find_win(int *rowp, int *colp, mouse_find_T popup);
|
win_T *mouse_find_win(int *rowp, int *colp, mouse_find_T popup);
|
||||||
int get_fpos_of_mouse(pos_T *mpos);
|
int get_fpos_of_mouse(pos_T *mpos);
|
||||||
int vcol2col(win_T *wp, linenr_T lnum, int vcol);
|
int vcol2col(win_T *wp, linenr_T lnum, int vcol);
|
||||||
|
22
src/ui.c
22
src/ui.c
@@ -3381,7 +3381,7 @@ retnomove:
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* compute the position in the buffer line from the posn on the screen */
|
/* compute the position in the buffer line from the posn on the screen */
|
||||||
if (mouse_comp_pos(curwin, &row, &col, &curwin->w_cursor.lnum))
|
if (mouse_comp_pos(curwin, &row, &col, &curwin->w_cursor.lnum, NULL))
|
||||||
mouse_past_bottom = TRUE;
|
mouse_past_bottom = TRUE;
|
||||||
|
|
||||||
/* Start Visual mode before coladvance(), for when 'sel' != "old" */
|
/* Start Visual mode before coladvance(), for when 'sel' != "old" */
|
||||||
@@ -3429,8 +3429,12 @@ retnomove:
|
|||||||
#if defined(FEAT_MOUSE) || defined(FEAT_TEXT_PROP) || defined(PROTO)
|
#if defined(FEAT_MOUSE) || defined(FEAT_TEXT_PROP) || defined(PROTO)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Compute the position in the buffer line from the posn on the screen in
|
* Compute the buffer line position from the screen position "rowp" / "colp" in
|
||||||
* window "win".
|
* window "win".
|
||||||
|
* "plines_cache" can be NULL (no cache) or an array with "win->w_height"
|
||||||
|
* entries that caches the plines_win() result from a previous call. Entry is
|
||||||
|
* zero if not computed yet. There must be no text or setting changes since
|
||||||
|
* the entry is put in the cache.
|
||||||
* Returns TRUE if the position is below the last line.
|
* Returns TRUE if the position is below the last line.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
@@ -3438,7 +3442,8 @@ mouse_comp_pos(
|
|||||||
win_T *win,
|
win_T *win,
|
||||||
int *rowp,
|
int *rowp,
|
||||||
int *colp,
|
int *colp,
|
||||||
linenr_T *lnump)
|
linenr_T *lnump,
|
||||||
|
int *plines_cache)
|
||||||
{
|
{
|
||||||
int col = *colp;
|
int col = *colp;
|
||||||
int row = *rowp;
|
int row = *rowp;
|
||||||
@@ -3456,6 +3461,12 @@ mouse_comp_pos(
|
|||||||
|
|
||||||
while (row > 0)
|
while (row > 0)
|
||||||
{
|
{
|
||||||
|
int cache_idx = lnum - win->w_topline;
|
||||||
|
|
||||||
|
if (plines_cache != NULL && plines_cache[cache_idx] > 0)
|
||||||
|
count = plines_cache[cache_idx];
|
||||||
|
else
|
||||||
|
{
|
||||||
#ifdef FEAT_DIFF
|
#ifdef FEAT_DIFF
|
||||||
/* Don't include filler lines in "count" */
|
/* Don't include filler lines in "count" */
|
||||||
if (win->w_p_diff
|
if (win->w_p_diff
|
||||||
@@ -3473,6 +3484,9 @@ mouse_comp_pos(
|
|||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
count = plines_win(win, lnum, TRUE);
|
count = plines_win(win, lnum, TRUE);
|
||||||
|
if (plines_cache != NULL)
|
||||||
|
plines_cache[cache_idx] = count;
|
||||||
|
}
|
||||||
if (count > row)
|
if (count > row)
|
||||||
break; /* Position is in this buffer line. */
|
break; /* Position is in this buffer line. */
|
||||||
#ifdef FEAT_FOLDING
|
#ifdef FEAT_FOLDING
|
||||||
@@ -3626,7 +3640,7 @@ get_fpos_of_mouse(pos_T *mpos)
|
|||||||
return IN_UNKNOWN;
|
return IN_UNKNOWN;
|
||||||
|
|
||||||
/* compute the position in the buffer line from the posn on the screen */
|
/* compute the position in the buffer line from the posn on the screen */
|
||||||
if (mouse_comp_pos(curwin, &row, &col, &mpos->lnum))
|
if (mouse_comp_pos(curwin, &row, &col, &mpos->lnum, NULL))
|
||||||
return IN_STATUS_LINE; /* past bottom */
|
return IN_STATUS_LINE; /* past bottom */
|
||||||
|
|
||||||
mpos->col = vcol2col(wp, mpos->lnum, col);
|
mpos->col = vcol2col(wp, mpos->lnum, col);
|
||||||
|
@@ -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 */
|
||||||
|
/**/
|
||||||
|
1751,
|
||||||
/**/
|
/**/
|
||||||
1750,
|
1750,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user