mirror of
https://github.com/neovim/neovim.git
synced 2024-12-24 13:15:09 -07:00
vim-patch:9.0.0886: horizontal mouse scroll only works in the GUI
Problem: Horizontal mouse scroll only works in the GUI.
Solution: Make horizontal mouse scroll also work in a terminal.
(Christopher Plewright, closes vim/vim#11448)
44c2209352
Co-authored-by: Christopher Plewright <chris@createng.com>
This commit is contained in:
parent
b75659c8fb
commit
bd3c1c7579
203
src/nvim/mouse.c
203
src/nvim/mouse.c
@ -993,48 +993,35 @@ void ins_mouse(int c)
|
|||||||
redraw_statuslines();
|
redraw_statuslines();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Implementation for scrolling in direction "dir", which is one of the MSCR_
|
||||||
|
/// values.
|
||||||
void ins_mousescroll(int dir)
|
void ins_mousescroll(int dir)
|
||||||
{
|
{
|
||||||
win_T *const old_curwin = curwin;
|
cmdarg_T cap;
|
||||||
pos_T tpos = curwin->w_cursor;
|
CLEAR_FIELD(cap);
|
||||||
|
|
||||||
if (mouse_row >= 0 && mouse_col >= 0) {
|
oparg_T oa;
|
||||||
int row = mouse_row, col = mouse_col, grid = mouse_grid;
|
clear_oparg(&oa);
|
||||||
|
cap.oap = &oa;
|
||||||
|
|
||||||
// find the window at the pointer coordinates
|
cap.arg = dir;
|
||||||
win_T *wp = mouse_find_win(&grid, &row, &col);
|
switch (dir) {
|
||||||
if (wp == NULL) {
|
case MSCR_UP:
|
||||||
return;
|
cap.cmdchar = K_MOUSEUP;
|
||||||
}
|
break;
|
||||||
curwin = wp;
|
case MSCR_DOWN:
|
||||||
curbuf = curwin->w_buffer;
|
cap.cmdchar = K_MOUSEDOWN;
|
||||||
}
|
break;
|
||||||
if (curwin == old_curwin) {
|
case MSCR_LEFT:
|
||||||
undisplay_dollar();
|
cap.cmdchar = K_MOUSELEFT;
|
||||||
}
|
break;
|
||||||
|
case MSCR_RIGHT:
|
||||||
// Don't scroll the window in which completion is being done.
|
cap.cmdchar = K_MOUSERIGHT;
|
||||||
if (!pum_visible() || curwin != old_curwin) {
|
break;
|
||||||
if (dir == MSCR_DOWN || dir == MSCR_UP) {
|
default:
|
||||||
if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) {
|
siemsg("Invalid ins_mousescroll() argument: %d", dir);
|
||||||
scroll_redraw(dir, curwin->w_botline - curwin->w_topline);
|
|
||||||
} else if (p_mousescroll_vert > 0) {
|
|
||||||
scroll_redraw(dir, (linenr_T)p_mousescroll_vert);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mouse_scroll_horiz(dir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
curwin->w_redr_status = true;
|
|
||||||
|
|
||||||
curwin = old_curwin;
|
|
||||||
curbuf = curwin->w_buffer;
|
|
||||||
|
|
||||||
if (!equalpos(curwin->w_cursor, tpos)) {
|
|
||||||
start_arrow(&tpos);
|
|
||||||
set_can_cindent(true);
|
|
||||||
}
|
}
|
||||||
|
do_mousescroll(MODE_INSERT, &cap);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return true if "c" is a mouse key.
|
/// Return true if "c" is a mouse key.
|
||||||
@ -1456,20 +1443,44 @@ retnomove:
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mouse scroll wheel: Default action is to scroll three lines, or one page
|
/// Make a horizontal scroll to "leftcol".
|
||||||
/// when Shift or Ctrl is used.
|
/// @return true if the cursor moved, false otherwise.
|
||||||
/// K_MOUSEUP (cap->arg == 1) or K_MOUSEDOWN (cap->arg == 0) or
|
static bool do_mousescroll_horiz(colnr_T leftcol)
|
||||||
/// K_MOUSELEFT (cap->arg == -1) or K_MOUSERIGHT (cap->arg == -2)
|
|
||||||
void nv_mousescroll(cmdarg_T *cap)
|
|
||||||
{
|
{
|
||||||
win_T *old_curwin = curwin;
|
if (curwin->w_p_wrap) {
|
||||||
|
return false; // no horizontal scrolling when wrapping
|
||||||
|
}
|
||||||
|
if (curwin->w_leftcol == leftcol) {
|
||||||
|
return false; // already there
|
||||||
|
}
|
||||||
|
|
||||||
|
// When the line of the cursor is too short, move the cursor to the
|
||||||
|
// longest visible line.
|
||||||
|
if (!virtual_active()
|
||||||
|
&& leftcol > scroll_line_len(curwin->w_cursor.lnum)) {
|
||||||
|
curwin->w_cursor.lnum = find_longest_lnum();
|
||||||
|
curwin->w_cursor.col = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return set_leftcol(leftcol);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Mouse scroll wheel: Default action is to scroll p_mousescroll_vert lines,
|
||||||
|
/// or p_mousescroll_hor, or one page when Shift or Ctrl is used.
|
||||||
|
/// Direction is indicated by "cap->arg":
|
||||||
|
/// K_MOUSEUP - MSCR_UP
|
||||||
|
/// K_MOUSEDOWN - MSCR_DOWN
|
||||||
|
/// K_MOUSELEFT - MSCR_LEFT
|
||||||
|
/// K_MOUSERIGHT - MSCR_RIGHT
|
||||||
|
void do_mousescroll(int mode, cmdarg_T *cap)
|
||||||
|
{
|
||||||
|
win_T *const old_curwin = curwin;
|
||||||
|
pos_T tpos = curwin->w_cursor;
|
||||||
|
|
||||||
if (mouse_row >= 0 && mouse_col >= 0) {
|
if (mouse_row >= 0 && mouse_col >= 0) {
|
||||||
int grid, row, col;
|
int grid = mouse_grid;
|
||||||
|
int row = mouse_row;
|
||||||
grid = mouse_grid;
|
int col = mouse_col;
|
||||||
row = mouse_row;
|
|
||||||
col = mouse_col;
|
|
||||||
|
|
||||||
// find the window at the pointer coordinates
|
// find the window at the pointer coordinates
|
||||||
win_T *wp = mouse_find_win(&grid, &row, &col);
|
win_T *wp = mouse_find_win(&grid, &row, &col);
|
||||||
@ -1480,18 +1491,45 @@ void nv_mousescroll(cmdarg_T *cap)
|
|||||||
curbuf = curwin->w_buffer;
|
curbuf = curwin->w_buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cap->arg == MSCR_UP || cap->arg == MSCR_DOWN) {
|
if (mode == MODE_INSERT && curwin == old_curwin) {
|
||||||
if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) {
|
undisplay_dollar();
|
||||||
(void)onepage(cap->arg ? FORWARD : BACKWARD, 1);
|
|
||||||
} else if (p_mousescroll_vert > 0) {
|
|
||||||
cap->count1 = (int)p_mousescroll_vert;
|
|
||||||
cap->count0 = (int)p_mousescroll_vert;
|
|
||||||
nv_scroll_line(cap);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mouse_scroll_horiz(cap->arg);
|
|
||||||
}
|
}
|
||||||
if (curwin != old_curwin && curwin->w_p_cul) {
|
|
||||||
|
// 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 (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) {
|
||||||
|
if (mode == MODE_INSERT) {
|
||||||
|
int step = curwin->w_botline - curwin->w_topline;
|
||||||
|
scroll_redraw(cap->arg, step);
|
||||||
|
} else {
|
||||||
|
(void)onepage(cap->arg ? FORWARD : BACKWARD, 1);
|
||||||
|
}
|
||||||
|
} else if (p_mousescroll_vert > 0) {
|
||||||
|
if (mode == MODE_INSERT) {
|
||||||
|
scroll_redraw(cap->arg, (linenr_T)p_mousescroll_vert);
|
||||||
|
} else {
|
||||||
|
cap->count1 = (int)p_mousescroll_vert;
|
||||||
|
cap->count0 = (int)p_mousescroll_vert;
|
||||||
|
nv_scroll_line(cap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
int step = (int)p_mousescroll_hor;
|
||||||
|
if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) {
|
||||||
|
step = curwin->w_width_inner;
|
||||||
|
}
|
||||||
|
|
||||||
|
colnr_T leftcol = curwin->w_leftcol + (cap->arg == MSCR_RIGHT ? -step : +step);
|
||||||
|
if (leftcol < 0) {
|
||||||
|
leftcol = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
(void)do_mousescroll_horiz(leftcol);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode == MODE_NORMAL && curwin != old_curwin && curwin->w_p_cul) {
|
||||||
redraw_for_cursorline(curwin);
|
redraw_for_cursorline(curwin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1499,6 +1537,18 @@ void nv_mousescroll(cmdarg_T *cap)
|
|||||||
|
|
||||||
curwin = old_curwin;
|
curwin = old_curwin;
|
||||||
curbuf = curwin->w_buffer;
|
curbuf = curwin->w_buffer;
|
||||||
|
|
||||||
|
if (mode == MODE_INSERT) {
|
||||||
|
if (!equalpos(curwin->w_cursor, tpos)) {
|
||||||
|
start_arrow(&tpos);
|
||||||
|
set_can_cindent(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void nv_mousescroll(cmdarg_T *cap)
|
||||||
|
{
|
||||||
|
do_mousescroll(MODE_NORMAL, cap);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Mouse clicks and drags.
|
/// Mouse clicks and drags.
|
||||||
@ -1724,9 +1774,7 @@ static colnr_T scroll_line_len(linenr_T lnum)
|
|||||||
return col;
|
return col;
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
|
||||||
/// Find longest visible line number.
|
/// Find longest visible line number.
|
||||||
///
|
|
||||||
static linenr_T find_longest_lnum(void)
|
static linenr_T find_longest_lnum(void)
|
||||||
{
|
{
|
||||||
linenr_T ret = 0;
|
linenr_T ret = 0;
|
||||||
@ -1761,39 +1809,6 @@ static linenr_T find_longest_lnum(void)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Do a horizontal scroll.
|
|
||||||
/// @return true if the cursor moved, false otherwise.
|
|
||||||
bool mouse_scroll_horiz(int dir)
|
|
||||||
{
|
|
||||||
if (curwin->w_p_wrap) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
int step = (int)p_mousescroll_hor;
|
|
||||||
if (mod_mask & (MOD_MASK_SHIFT | MOD_MASK_CTRL)) {
|
|
||||||
step = curwin->w_width_inner;
|
|
||||||
}
|
|
||||||
|
|
||||||
int leftcol = curwin->w_leftcol + (dir == MSCR_RIGHT ? -step : +step);
|
|
||||||
if (leftcol < 0) {
|
|
||||||
leftcol = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (curwin->w_leftcol == leftcol) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// When the line of the cursor is too short, move the cursor to the
|
|
||||||
// longest visible line.
|
|
||||||
if (!virtual_active()
|
|
||||||
&& (colnr_T)leftcol > scroll_line_len(curwin->w_cursor.lnum)) {
|
|
||||||
curwin->w_cursor.lnum = find_longest_lnum();
|
|
||||||
curwin->w_cursor.col = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return set_leftcol(leftcol);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Check clicked cell on its grid
|
/// Check clicked cell on its grid
|
||||||
static void mouse_check_grid(colnr_T *vcolp, int *flagsp)
|
static void mouse_check_grid(colnr_T *vcolp, int *flagsp)
|
||||||
FUNC_ATTR_NONNULL_ALL
|
FUNC_ATTR_NONNULL_ALL
|
||||||
|
Loading…
Reference in New Issue
Block a user