Mercurial > vim
comparison src/ui.c @ 31103:33ca088dbd3e v9.0.0886
patch 9.0.0886: horizontal mouse scroll only works in the GUI
Commit: https://github.com/vim/vim/commit/44c2209352d56d70b1fc0215e81f1822d55aa563
Author: Christopher Plewright <chris@createng.com>
Date: Tue Nov 15 17:43:36 2022 +0000
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)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Tue, 15 Nov 2022 18:45:03 +0100 |
parents | 71137f73c94d |
children | fa309d9af73c |
comparison
equal
deleted
inserted
replaced
31102:71da2abdd899 | 31103:33ca088dbd3e |
---|---|
1124 return screen_Rows - 1; | 1124 return screen_Rows - 1; |
1125 return row; | 1125 return row; |
1126 } | 1126 } |
1127 | 1127 |
1128 /* | 1128 /* |
1129 * Return length of line "lnum" in screen cells for horizontal scrolling. | |
1130 */ | |
1131 long | |
1132 scroll_line_len(linenr_T lnum) | |
1133 { | |
1134 char_u *p = ml_get(lnum); | |
1135 colnr_T col = 0; | |
1136 | |
1137 if (*p != NUL) | |
1138 for (;;) | |
1139 { | |
1140 int w = chartabsize(p, col); | |
1141 MB_PTR_ADV(p); | |
1142 if (*p == NUL) // don't count the last character | |
1143 break; | |
1144 col += w; | |
1145 } | |
1146 return col; | |
1147 } | |
1148 | |
1149 /* | |
1150 * Find the longest visible line number. This is used for horizontal | |
1151 * scrolling. If this is not possible (or not desired, by setting 'h' in | |
1152 * "guioptions") then the current line number is returned. | |
1153 */ | |
1154 linenr_T | |
1155 ui_find_longest_lnum(void) | |
1156 { | |
1157 linenr_T ret = 0; | |
1158 | |
1159 // Calculate maximum for horizontal scrollbar. Check for reasonable | |
1160 // line numbers, topline and botline can be invalid when displaying is | |
1161 // postponed. | |
1162 if ( | |
1163 # ifdef FEAT_GUI | |
1164 (!gui.in_use || vim_strchr(p_go, GO_HORSCROLL) == NULL) && | |
1165 # endif | |
1166 curwin->w_topline <= curwin->w_cursor.lnum | |
1167 && curwin->w_botline > curwin->w_cursor.lnum | |
1168 && curwin->w_botline <= curbuf->b_ml.ml_line_count + 1) | |
1169 { | |
1170 linenr_T lnum; | |
1171 long n; | |
1172 long max = 0; | |
1173 | |
1174 // Use maximum of all visible lines. Remember the lnum of the | |
1175 // longest line, closest to the cursor line. Used when scrolling | |
1176 // below. | |
1177 for (lnum = curwin->w_topline; lnum < curwin->w_botline; ++lnum) | |
1178 { | |
1179 n = scroll_line_len(lnum); | |
1180 if (n > max) | |
1181 { | |
1182 max = n; | |
1183 ret = lnum; | |
1184 } | |
1185 else if (n == max && abs((int)(lnum - curwin->w_cursor.lnum)) | |
1186 < abs((int)(ret - curwin->w_cursor.lnum))) | |
1187 ret = lnum; | |
1188 } | |
1189 } | |
1190 else | |
1191 // Use cursor line only. | |
1192 ret = curwin->w_cursor.lnum; | |
1193 | |
1194 return ret; | |
1195 } | |
1196 | |
1197 /* | |
1129 * Called when focus changed. Used for the GUI or for systems where this can | 1198 * Called when focus changed. Used for the GUI or for systems where this can |
1130 * be done in the console (Win32). | 1199 * be done in the console (Win32). |
1131 */ | 1200 */ |
1132 void | 1201 void |
1133 ui_focus_change( | 1202 ui_focus_change( |