0
0
mirror of https://github.com/vim/vim.git synced 2025-09-27 04:14:06 -04:00

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 #11448)
This commit is contained in:
Christopher Plewright
2022-11-15 17:43:36 +00:00
committed by Bram Moolenaar
parent b53a190e9f
commit 44c2209352
10 changed files with 234 additions and 247 deletions

123
src/gui.c
View File

@@ -4105,14 +4105,14 @@ gui_drag_scrollbar(scrollbar_T *sb, long value, int still_dragging)
scrollbar_value = value;
if (State & MODE_NORMAL)
gui_do_horiz_scroll(scrollbar_value, FALSE);
do_mousescroll_horiz(scrollbar_value);
else if (State & MODE_INSERT)
ins_horscroll();
else if (State & MODE_CMDLINE)
{
if (msg_scrolled == 0)
{
gui_do_horiz_scroll(scrollbar_value, FALSE);
do_mousescroll_horiz(scrollbar_value);
redrawcmdline();
}
}
@@ -4504,88 +4504,13 @@ gui_do_scroll(void)
return (wp == curwin && !EQUAL_POS(curwin->w_cursor, old_cursor));
}
/*
* Horizontal scrollbar stuff:
*/
/*
* Return length of line "lnum" for horizontal scrolling.
*/
static colnr_T
scroll_line_len(linenr_T lnum)
{
char_u *p;
colnr_T col;
int w;
p = ml_get(lnum);
col = 0;
if (*p != NUL)
for (;;)
{
w = chartabsize(p, col);
MB_PTR_ADV(p);
if (*p == NUL) // don't count the last character
break;
col += w;
}
return col;
}
// Remember which line is currently the longest, so that we don't have to
// search for it when scrolling horizontally.
static linenr_T longest_lnum = 0;
/*
* Find longest visible line number. If this is not possible (or not desired,
* by setting 'h' in "guioptions") then the current line number is returned.
*/
static linenr_T
gui_find_longest_lnum(void)
{
linenr_T ret = 0;
// Calculate maximum for horizontal scrollbar. Check for reasonable
// line numbers, topline and botline can be invalid when displaying is
// postponed.
if (vim_strchr(p_go, GO_HORSCROLL) == NULL
&& curwin->w_topline <= curwin->w_cursor.lnum
&& curwin->w_botline > curwin->w_cursor.lnum
&& curwin->w_botline <= curbuf->b_ml.ml_line_count + 1)
{
linenr_T lnum;
colnr_T n;
long max = 0;
// Use maximum of all visible lines. Remember the lnum of the
// longest line, closest to the cursor line. Used when scrolling
// below.
for (lnum = curwin->w_topline; lnum < curwin->w_botline; ++lnum)
{
n = scroll_line_len(lnum);
if (n > (colnr_T)max)
{
max = n;
ret = lnum;
}
else if (n == (colnr_T)max
&& abs((int)(lnum - curwin->w_cursor.lnum))
< abs((int)(ret - curwin->w_cursor.lnum)))
ret = lnum;
}
}
else
// Use cursor line only.
ret = curwin->w_cursor.lnum;
return ret;
}
static void
gui_update_horiz_scrollbar(int force)
{
long value, size, max; // need 32 bit ints here
long value, size, max;
if (!gui.which_scrollbars[SBAR_BOTTOM])
return;
@@ -4619,9 +4544,7 @@ gui_update_horiz_scrollbar(int force)
else
{
value = curwin->w_leftcol;
longest_lnum = gui_find_longest_lnum();
max = scroll_line_len(longest_lnum);
max = scroll_line_len(ui_find_longest_lnum());
if (virtual_active())
{
@@ -4669,44 +4592,6 @@ gui_update_horiz_scrollbar(int force)
gui_mch_set_scrollbar_thumb(&gui.bottom_sbar, value, size, max);
}
/*
* Do a horizontal scroll. Return TRUE if the cursor moved, FALSE otherwise.
*/
int
gui_do_horiz_scroll(long_u leftcol, int compute_longest_lnum)
{
// no wrapping, no scrolling
if (curwin->w_p_wrap)
return FALSE;
if (curwin->w_leftcol == (colnr_T)leftcol)
return FALSE;
curwin->w_leftcol = (colnr_T)leftcol;
// When the line of the cursor is too short, move the cursor to the
// longest visible line.
if (vim_strchr(p_go, GO_HORSCROLL) == NULL
&& !virtual_active()
&& (colnr_T)leftcol > scroll_line_len(curwin->w_cursor.lnum))
{
if (compute_longest_lnum)
{
curwin->w_cursor.lnum = gui_find_longest_lnum();
curwin->w_cursor.col = 0;
}
// Do a sanity check on "longest_lnum", just in case.
else if (longest_lnum >= curwin->w_topline
&& longest_lnum < curwin->w_botline)
{
curwin->w_cursor.lnum = longest_lnum;
curwin->w_cursor.col = 0;
}
}
return leftcol_changed();
}
/*
* Check that none of the colors are the same as the background color
*/