mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -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:
committed by
Bram Moolenaar
parent
b53a190e9f
commit
44c2209352
69
src/ui.c
69
src/ui.c
@@ -1125,6 +1125,75 @@ check_row(int row)
|
||||
return row;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return length of line "lnum" in screen cells for horizontal scrolling.
|
||||
*/
|
||||
long
|
||||
scroll_line_len(linenr_T lnum)
|
||||
{
|
||||
char_u *p = ml_get(lnum);
|
||||
colnr_T col = 0;
|
||||
|
||||
if (*p != NUL)
|
||||
for (;;)
|
||||
{
|
||||
int w = chartabsize(p, col);
|
||||
MB_PTR_ADV(p);
|
||||
if (*p == NUL) // don't count the last character
|
||||
break;
|
||||
col += w;
|
||||
}
|
||||
return col;
|
||||
}
|
||||
|
||||
/*
|
||||
* Find the longest visible line number. This is used for horizontal
|
||||
* scrolling. If this is not possible (or not desired, by setting 'h' in
|
||||
* "guioptions") then the current line number is returned.
|
||||
*/
|
||||
linenr_T
|
||||
ui_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 (
|
||||
# ifdef FEAT_GUI
|
||||
(!gui.in_use || vim_strchr(p_go, GO_HORSCROLL) == NULL) &&
|
||||
# endif
|
||||
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;
|
||||
long 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 > max)
|
||||
{
|
||||
max = n;
|
||||
ret = lnum;
|
||||
}
|
||||
else if (n == 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;
|
||||
}
|
||||
|
||||
/*
|
||||
* Called when focus changed. Used for the GUI or for systems where this can
|
||||
* be done in the console (Win32).
|
||||
|
Reference in New Issue
Block a user