mirror of
https://github.com/vim/vim.git
synced 2025-09-23 03:43:49 -04:00
patch 9.0.0902: some mouse scroll code is not in a good place
Problem: Some mouse scroll code is not in a good place. Solution: Refactor the code. (Christopher Plewright, closes #11561)
This commit is contained in:
committed by
Bram Moolenaar
parent
0c34d56264
commit
696d0a8625
142
src/mouse.c
142
src/mouse.c
@@ -1102,20 +1102,19 @@ ins_mouse(int c)
|
||||
}
|
||||
|
||||
/*
|
||||
* Implementation for scrolling in direction "dir", which is one of the MSCR_
|
||||
* values.
|
||||
* Implementation for scrolling in Insert mode in direction "dir", which is one
|
||||
* of the MSCR_ values.
|
||||
*/
|
||||
void
|
||||
ins_mousescroll(int dir)
|
||||
{
|
||||
cmdarg_T cap;
|
||||
CLEAR_FIELD(cap);
|
||||
|
||||
oparg_T oa;
|
||||
CLEAR_FIELD(cap);
|
||||
clear_oparg(&oa);
|
||||
cap.oap = &oa;
|
||||
|
||||
cap.arg = dir;
|
||||
|
||||
switch (dir)
|
||||
{
|
||||
case MSCR_UP:
|
||||
@@ -1133,7 +1132,50 @@ ins_mousescroll(int dir)
|
||||
default:
|
||||
siemsg("Invalid ins_mousescroll() argument: %d", dir);
|
||||
}
|
||||
do_mousescroll(MODE_INSERT, &cap);
|
||||
|
||||
win_T *wp = curwin;
|
||||
if (mouse_row >= 0 && mouse_col >= 0)
|
||||
{
|
||||
// Find the window at the mouse pointer coordinates.
|
||||
int row = mouse_row;
|
||||
int col = mouse_col;
|
||||
wp = mouse_find_win(&row, &col, FIND_POPUP);
|
||||
if (wp == NULL)
|
||||
return;
|
||||
}
|
||||
|
||||
if (wp == curwin)
|
||||
{
|
||||
// Don't scroll the current window if the popup menu is visible.
|
||||
if (pum_visible())
|
||||
return;
|
||||
|
||||
undisplay_dollar();
|
||||
}
|
||||
|
||||
linenr_T orig_topline = wp->w_topline;
|
||||
colnr_T orig_leftcol = wp->w_leftcol;
|
||||
pos_T orig_cursor = curwin->w_cursor;
|
||||
|
||||
// The scrolling works almost the same way as in Normal mode.
|
||||
nv_mousescroll(&cap);
|
||||
|
||||
// If the window actually scrolled and the popup menu may overlay the
|
||||
// window, need to redraw it.
|
||||
if ((orig_topline != wp->w_topline || orig_leftcol != wp->w_leftcol)
|
||||
&& pum_visible())
|
||||
{
|
||||
// TODO: Would be more efficient to only redraw the windows that are
|
||||
// overlapped by the popup menu.
|
||||
redraw_all_later(UPD_NOT_VALID);
|
||||
ins_compl_show_pum();
|
||||
}
|
||||
|
||||
if (!EQUAL_POS(curwin->w_cursor, orig_cursor))
|
||||
{
|
||||
start_arrow(&orig_cursor);
|
||||
set_can_cindent(TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -2062,32 +2104,29 @@ do_mousescroll_horiz(long_u leftcol)
|
||||
* K_MOUSERIGHT - MSCR_RIGHT
|
||||
*/
|
||||
void
|
||||
do_mousescroll(int mode, cmdarg_T *cap)
|
||||
nv_mousescroll(cmdarg_T *cap)
|
||||
{
|
||||
win_T *old_curwin = curwin, *wp;
|
||||
int did_ins_scroll = FALSE;
|
||||
pos_T tpos = curwin->w_cursor;
|
||||
win_T *old_curwin = curwin;
|
||||
|
||||
if (mouse_row >= 0 && mouse_col >= 0)
|
||||
{
|
||||
int row, col;
|
||||
|
||||
row = mouse_row;
|
||||
col = mouse_col;
|
||||
|
||||
// find the window at the pointer coordinates
|
||||
wp = mouse_find_win(&row, &col, FIND_POPUP);
|
||||
// Find the window at the mouse pointer coordinates.
|
||||
int row = mouse_row;
|
||||
int col = mouse_col;
|
||||
win_T *wp = mouse_find_win(&row, &col, FIND_POPUP);
|
||||
if (wp == NULL)
|
||||
return;
|
||||
#ifdef FEAT_PROP_POPUP
|
||||
if (WIN_IS_POPUP(wp) && !wp->w_has_scrollbar)
|
||||
// cannot scroll this popup window
|
||||
return;
|
||||
#endif
|
||||
// NOTE: Must restore "curwin" to "old_curwin" before returning!
|
||||
curwin = wp;
|
||||
curbuf = curwin->w_buffer;
|
||||
}
|
||||
if (mode == MODE_INSERT && curwin == old_curwin)
|
||||
undisplay_dollar();
|
||||
|
||||
int shift_or_ctrl = mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL);
|
||||
|
||||
#ifdef FEAT_TERMINAL
|
||||
if (term_use_loop())
|
||||
@@ -2096,35 +2135,23 @@ do_mousescroll(int mode, cmdarg_T *cap)
|
||||
send_keys_to_term(curbuf->b_term, cap->cmdchar, mod_mask, FALSE);
|
||||
else
|
||||
#endif
|
||||
// For Insert mode, don't scroll the window in which completion is being
|
||||
// done.
|
||||
if (mode == MODE_NORMAL || !pum_visible() || curwin != old_curwin)
|
||||
{
|
||||
if (cap->arg == MSCR_UP || cap->arg == MSCR_DOWN)
|
||||
{
|
||||
if (mouse_vert_step < 0
|
||||
|| mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL))
|
||||
// Vertical scrolling
|
||||
if (!(State & MODE_INSERT) && (mouse_vert_step < 0 || shift_or_ctrl))
|
||||
{
|
||||
if (mode == MODE_INSERT)
|
||||
{
|
||||
long step = (long)(curwin->w_botline - curwin->w_topline);
|
||||
scroll_redraw(cap->arg, step);
|
||||
// whole page up or down
|
||||
onepage(cap->arg == MSCR_UP ? FORWARD : BACKWARD, 1L);
|
||||
}
|
||||
else
|
||||
{
|
||||
did_ins_scroll = onepage(cap->arg ? FORWARD : BACKWARD, 1L);
|
||||
}
|
||||
}
|
||||
else
|
||||
if (mouse_vert_step < 0 || shift_or_ctrl)
|
||||
{
|
||||
if (mode == MODE_INSERT)
|
||||
{
|
||||
scroll_redraw(cap->arg, mouse_vert_step);
|
||||
// whole page up or down
|
||||
cap->count1 = (long)(curwin->w_botline - curwin->w_topline);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Don't scroll more than half the window height.
|
||||
if (curwin->w_height < mouse_vert_step * 2)
|
||||
else if (curwin->w_height < mouse_vert_step * 2)
|
||||
{
|
||||
cap->count1 = curwin->w_height / 2;
|
||||
if (cap->count1 == 0)
|
||||
@@ -2137,7 +2164,6 @@ do_mousescroll(int mode, cmdarg_T *cap)
|
||||
cap->count0 = cap->count1;
|
||||
nv_scroll_line(cap);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef FEAT_PROP_POPUP
|
||||
if (WIN_IS_POPUP(curwin))
|
||||
@@ -2146,20 +2172,18 @@ do_mousescroll(int mode, cmdarg_T *cap)
|
||||
}
|
||||
else
|
||||
{
|
||||
long step = (mouse_hor_step < 0
|
||||
|| (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)))
|
||||
// Horizontal scrolling
|
||||
long step = (mouse_hor_step < 0 || shift_or_ctrl)
|
||||
? curwin->w_width : mouse_hor_step;
|
||||
long leftcol = curwin->w_leftcol
|
||||
+ (cap->arg == MSCR_RIGHT ? -step : step);
|
||||
if (leftcol < 0)
|
||||
leftcol = 0;
|
||||
|
||||
did_ins_scroll = do_mousescroll_horiz((long_u)leftcol);
|
||||
}
|
||||
do_mousescroll_horiz((long_u)leftcol);
|
||||
}
|
||||
|
||||
#ifdef FEAT_SYN_HL
|
||||
if (mode == MODE_NORMAL && curwin != old_curwin && curwin->w_p_cul)
|
||||
if (curwin != old_curwin && curwin->w_p_cul)
|
||||
redraw_for_cursorline(curwin);
|
||||
#endif
|
||||
may_trigger_winscrolled();
|
||||
@@ -2168,29 +2192,6 @@ do_mousescroll(int mode, cmdarg_T *cap)
|
||||
|
||||
curwin = old_curwin;
|
||||
curbuf = curwin->w_buffer;
|
||||
|
||||
if (mode == MODE_INSERT)
|
||||
{
|
||||
// The popup menu may overlay the window, need to redraw it.
|
||||
// TODO: Would be more efficient to only redraw the windows that are
|
||||
// overlapped by the popup menu.
|
||||
if (pum_visible() && did_ins_scroll)
|
||||
{
|
||||
redraw_all_later(UPD_NOT_VALID);
|
||||
ins_compl_show_pum();
|
||||
}
|
||||
if (!EQUAL_POS(curwin->w_cursor, tpos))
|
||||
{
|
||||
start_arrow(&tpos);
|
||||
set_can_cindent(TRUE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nv_mousescroll(cmdarg_T *cap)
|
||||
{
|
||||
do_mousescroll(MODE_NORMAL, cap);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -3162,6 +3163,9 @@ vcol2col(win_T *wp, linenr_T lnum, int vcol)
|
||||
#endif
|
||||
|
||||
#if defined(FEAT_EVAL) || defined(PROTO)
|
||||
/*
|
||||
* "getmousepos()" function.
|
||||
*/
|
||||
void
|
||||
f_getmousepos(typval_T *argvars UNUSED, typval_T *rettv)
|
||||
{
|
||||
|
@@ -15,7 +15,6 @@ int mouse_model_popup(void);
|
||||
void reset_dragwin(void);
|
||||
int jump_to_mouse(int flags, int *inclusive, int which_button);
|
||||
int do_mousescroll_horiz(long_u leftcol);
|
||||
void do_mousescroll(int mode, cmdarg_T *cap);
|
||||
void nv_mousescroll(cmdarg_T *cap);
|
||||
void nv_mouse(cmdarg_T *cap);
|
||||
void reset_held_button(void);
|
||||
|
@@ -695,6 +695,8 @@ static char *(features[]) =
|
||||
|
||||
static int included_patches[] =
|
||||
{ /* Add new patch number below this line */
|
||||
/**/
|
||||
902,
|
||||
/**/
|
||||
901,
|
||||
/**/
|
||||
|
Reference in New Issue
Block a user