Mercurial > vim
annotate src/move.c @ 14724:90de24a1e9b7 v8.1.0374
patch 8.1.0374: moving the cursor is slow when 'relativenumber' is set
commit https://github.com/vim/vim/commit/bd9a53c06c8869ad811cb3dd01a309c9be7d7a63
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Sep 12 23:15:48 2018 +0200
patch 8.1.0374: moving the cursor is slow when 'relativenumber' is set
Problem: Moving the cursor is slow when 'relativenumber' is set.
Solution: Only redraw the number column, not all lines.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Wed, 12 Sep 2018 23:30:06 +0200 |
parents | 9b150311eb9c |
children | 10107703b9b2 |
rev | line source |
---|---|
10042
4aead6a9b7a9
commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents:
9852
diff
changeset
|
1 /* vi:set ts=8 sts=4 sw=4 noet: |
7 | 2 * |
3 * VIM - Vi IMproved by Bram Moolenaar | |
4 * | |
5 * Do ":help uganda" in Vim to read copying and usage conditions. | |
6 * Do ":help credits" in Vim to see a list of people who contributed. | |
7 * See README.txt for an overview of the Vim source code. | |
8 */ | |
9 /* | |
10 * move.c: Functions for moving the cursor and scrolling text. | |
11 * | |
12 * There are two ways to move the cursor: | |
13 * 1. Move the cursor directly, the text is scrolled to keep the cursor in the | |
14 * window. | |
15 * 2. Scroll the text, the cursor is moved into the text visible in the | |
16 * window. | |
17 * The 'scrolloff' option makes this a bit complicated. | |
18 */ | |
19 | |
20 #include "vim.h" | |
21 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7103
diff
changeset
|
22 static void comp_botline(win_T *wp); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7103
diff
changeset
|
23 static void redraw_for_cursorline(win_T *wp); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7103
diff
changeset
|
24 static int scrolljump_value(void); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7103
diff
changeset
|
25 static int check_top_offset(void); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7103
diff
changeset
|
26 static void curs_rows(win_T *wp); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7103
diff
changeset
|
27 static void validate_cheight(void); |
7 | 28 |
29 typedef struct | |
30 { | |
31 linenr_T lnum; /* line number */ | |
32 #ifdef FEAT_DIFF | |
33 int fill; /* filler lines */ | |
34 #endif | |
35 int height; /* height of added line */ | |
36 } lineoff_T; | |
37 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7103
diff
changeset
|
38 static void topline_back(lineoff_T *lp); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7103
diff
changeset
|
39 static void botline_forw(lineoff_T *lp); |
7 | 40 #ifdef FEAT_DIFF |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7103
diff
changeset
|
41 static void botline_topline(lineoff_T *lp); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7103
diff
changeset
|
42 static void topline_botline(lineoff_T *lp); |
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7103
diff
changeset
|
43 static void max_topfill(void); |
7 | 44 #endif |
45 | |
46 /* | |
47 * Compute wp->w_botline for the current wp->w_topline. Can be called after | |
48 * wp->w_topline changed. | |
49 */ | |
50 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
51 comp_botline(win_T *wp) |
7 | 52 { |
53 int n; | |
54 linenr_T lnum; | |
55 int done; | |
56 #ifdef FEAT_FOLDING | |
57 linenr_T last; | |
58 int folded; | |
59 #endif | |
60 | |
61 /* | |
62 * If w_cline_row is valid, start there. | |
63 * Otherwise have to start at w_topline. | |
64 */ | |
65 check_cursor_moved(wp); | |
66 if (wp->w_valid & VALID_CROW) | |
67 { | |
68 lnum = wp->w_cursor.lnum; | |
69 done = wp->w_cline_row; | |
70 } | |
71 else | |
72 { | |
73 lnum = wp->w_topline; | |
74 done = 0; | |
75 } | |
76 | |
77 for ( ; lnum <= wp->w_buffer->b_ml.ml_line_count; ++lnum) | |
78 { | |
79 #ifdef FEAT_FOLDING | |
80 last = lnum; | |
81 folded = FALSE; | |
82 if (hasFoldingWin(wp, lnum, NULL, &last, TRUE, NULL)) | |
83 { | |
84 n = 1; | |
85 folded = TRUE; | |
86 } | |
87 else | |
88 #endif | |
89 #ifdef FEAT_DIFF | |
90 if (lnum == wp->w_topline) | |
91 n = plines_win_nofill(wp, lnum, TRUE) + wp->w_topfill; | |
92 else | |
93 #endif | |
94 n = plines_win(wp, lnum, TRUE); | |
95 if ( | |
96 #ifdef FEAT_FOLDING | |
97 lnum <= wp->w_cursor.lnum && last >= wp->w_cursor.lnum | |
98 #else | |
99 lnum == wp->w_cursor.lnum | |
100 #endif | |
101 ) | |
102 { | |
103 wp->w_cline_row = done; | |
104 wp->w_cline_height = n; | |
105 #ifdef FEAT_FOLDING | |
106 wp->w_cline_folded = folded; | |
107 #endif | |
5764 | 108 redraw_for_cursorline(wp); |
7 | 109 wp->w_valid |= (VALID_CROW|VALID_CHEIGHT); |
110 } | |
111 if (done + n > wp->w_height) | |
112 break; | |
113 done += n; | |
114 #ifdef FEAT_FOLDING | |
115 lnum = last; | |
116 #endif | |
117 } | |
118 | |
119 /* wp->w_botline is the line that is just below the window */ | |
120 wp->w_botline = lnum; | |
121 wp->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP; | |
122 | |
123 set_empty_rows(wp, done); | |
124 } | |
125 | |
14720
a9665096074b
patch 8.1.0372: screen updating slow when 'cursorline' is set
Christian Brabandt <cb@256bit.org>
parents:
14317
diff
changeset
|
126 #ifdef FEAT_SYN_HL |
a9665096074b
patch 8.1.0372: screen updating slow when 'cursorline' is set
Christian Brabandt <cb@256bit.org>
parents:
14317
diff
changeset
|
127 static linenr_T last_cursorline = 0; |
a9665096074b
patch 8.1.0372: screen updating slow when 'cursorline' is set
Christian Brabandt <cb@256bit.org>
parents:
14317
diff
changeset
|
128 #endif |
a9665096074b
patch 8.1.0372: screen updating slow when 'cursorline' is set
Christian Brabandt <cb@256bit.org>
parents:
14317
diff
changeset
|
129 |
7 | 130 /* |
5764 | 131 * Redraw when w_cline_row changes and 'relativenumber' or 'cursorline' is |
132 * set. | |
133 */ | |
134 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
135 redraw_for_cursorline(win_T *wp) |
5764 | 136 { |
137 if ((wp->w_p_rnu | |
138 #ifdef FEAT_SYN_HL | |
139 || wp->w_p_cul | |
140 #endif | |
141 ) | |
142 && (wp->w_valid & VALID_CROW) == 0 | |
143 # ifdef FEAT_INS_EXPAND | |
144 && !pum_visible() | |
145 # endif | |
146 ) | |
14720
a9665096074b
patch 8.1.0372: screen updating slow when 'cursorline' is set
Christian Brabandt <cb@256bit.org>
parents:
14317
diff
changeset
|
147 { |
14724
90de24a1e9b7
patch 8.1.0374: moving the cursor is slow when 'relativenumber' is set
Christian Brabandt <cb@256bit.org>
parents:
14722
diff
changeset
|
148 if (wp->w_p_rnu) |
90de24a1e9b7
patch 8.1.0374: moving the cursor is slow when 'relativenumber' is set
Christian Brabandt <cb@256bit.org>
parents:
14722
diff
changeset
|
149 // win_line() will redraw the number column only. |
90de24a1e9b7
patch 8.1.0374: moving the cursor is slow when 'relativenumber' is set
Christian Brabandt <cb@256bit.org>
parents:
14722
diff
changeset
|
150 redraw_win_later(wp, VALID); |
14720
a9665096074b
patch 8.1.0372: screen updating slow when 'cursorline' is set
Christian Brabandt <cb@256bit.org>
parents:
14317
diff
changeset
|
151 #ifdef FEAT_SYN_HL |
14724
90de24a1e9b7
patch 8.1.0374: moving the cursor is slow when 'relativenumber' is set
Christian Brabandt <cb@256bit.org>
parents:
14722
diff
changeset
|
152 if (wp->w_p_cul) |
14720
a9665096074b
patch 8.1.0372: screen updating slow when 'cursorline' is set
Christian Brabandt <cb@256bit.org>
parents:
14317
diff
changeset
|
153 { |
14724
90de24a1e9b7
patch 8.1.0374: moving the cursor is slow when 'relativenumber' is set
Christian Brabandt <cb@256bit.org>
parents:
14722
diff
changeset
|
154 if (wp->w_redr_type <= VALID && last_cursorline != 0) |
90de24a1e9b7
patch 8.1.0374: moving the cursor is slow when 'relativenumber' is set
Christian Brabandt <cb@256bit.org>
parents:
14722
diff
changeset
|
155 { |
90de24a1e9b7
patch 8.1.0374: moving the cursor is slow when 'relativenumber' is set
Christian Brabandt <cb@256bit.org>
parents:
14722
diff
changeset
|
156 // "last_cursorline" may be set for another window, worst case |
90de24a1e9b7
patch 8.1.0374: moving the cursor is slow when 'relativenumber' is set
Christian Brabandt <cb@256bit.org>
parents:
14722
diff
changeset
|
157 // we redraw too much. This is optimized for moving the cursor |
90de24a1e9b7
patch 8.1.0374: moving the cursor is slow when 'relativenumber' is set
Christian Brabandt <cb@256bit.org>
parents:
14722
diff
changeset
|
158 // around in the same window. |
90de24a1e9b7
patch 8.1.0374: moving the cursor is slow when 'relativenumber' is set
Christian Brabandt <cb@256bit.org>
parents:
14722
diff
changeset
|
159 redrawWinline(wp, last_cursorline, FALSE); |
90de24a1e9b7
patch 8.1.0374: moving the cursor is slow when 'relativenumber' is set
Christian Brabandt <cb@256bit.org>
parents:
14722
diff
changeset
|
160 redrawWinline(wp, wp->w_cursor.lnum, FALSE); |
90de24a1e9b7
patch 8.1.0374: moving the cursor is slow when 'relativenumber' is set
Christian Brabandt <cb@256bit.org>
parents:
14722
diff
changeset
|
161 redraw_win_later(wp, VALID); |
90de24a1e9b7
patch 8.1.0374: moving the cursor is slow when 'relativenumber' is set
Christian Brabandt <cb@256bit.org>
parents:
14722
diff
changeset
|
162 } |
90de24a1e9b7
patch 8.1.0374: moving the cursor is slow when 'relativenumber' is set
Christian Brabandt <cb@256bit.org>
parents:
14722
diff
changeset
|
163 else |
90de24a1e9b7
patch 8.1.0374: moving the cursor is slow when 'relativenumber' is set
Christian Brabandt <cb@256bit.org>
parents:
14722
diff
changeset
|
164 redraw_win_later(wp, SOME_VALID); |
90de24a1e9b7
patch 8.1.0374: moving the cursor is slow when 'relativenumber' is set
Christian Brabandt <cb@256bit.org>
parents:
14722
diff
changeset
|
165 last_cursorline = wp->w_cursor.lnum; |
14720
a9665096074b
patch 8.1.0372: screen updating slow when 'cursorline' is set
Christian Brabandt <cb@256bit.org>
parents:
14317
diff
changeset
|
166 } |
14722
9b150311eb9c
patch 8.1.0373: screen updating still slow when 'cursorline' is set
Christian Brabandt <cb@256bit.org>
parents:
14720
diff
changeset
|
167 #endif |
14720
a9665096074b
patch 8.1.0372: screen updating slow when 'cursorline' is set
Christian Brabandt <cb@256bit.org>
parents:
14317
diff
changeset
|
168 } |
5764 | 169 } |
170 | |
171 /* | |
7 | 172 * Update curwin->w_topline and redraw if necessary. |
173 * Used to update the screen before printing a message. | |
174 */ | |
175 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
176 update_topline_redraw(void) |
7 | 177 { |
178 update_topline(); | |
179 if (must_redraw) | |
180 update_screen(0); | |
181 } | |
182 | |
183 /* | |
184 * Update curwin->w_topline to move the cursor onto the screen. | |
185 */ | |
186 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
187 update_topline(void) |
7 | 188 { |
189 long line_count; | |
190 int halfheight; | |
191 int n; | |
192 linenr_T old_topline; | |
193 #ifdef FEAT_DIFF | |
194 int old_topfill; | |
195 #endif | |
196 #ifdef FEAT_FOLDING | |
197 linenr_T lnum; | |
198 #endif | |
199 int check_topline = FALSE; | |
200 int check_botline = FALSE; | |
201 #ifdef FEAT_MOUSE | |
202 int save_so = p_so; | |
203 #endif | |
204 | |
11258
84f71a8a5f2c
patch 8.0.0515: ml_get errors in silent Ex mode
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
205 /* If there is no valid screen and when the window height is zero just use |
84f71a8a5f2c
patch 8.0.0515: ml_get errors in silent Ex mode
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
206 * the cursor line. */ |
84f71a8a5f2c
patch 8.0.0515: ml_get errors in silent Ex mode
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
207 if (!screen_valid(TRUE) || curwin->w_height == 0) |
6247 | 208 { |
209 curwin->w_topline = curwin->w_cursor.lnum; | |
210 curwin->w_botline = curwin->w_topline; | |
211 curwin->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP; | |
212 curwin->w_scbind_pos = 1; | |
213 return; | |
214 } | |
215 | |
7 | 216 check_cursor_moved(curwin); |
217 if (curwin->w_valid & VALID_TOPLINE) | |
218 return; | |
219 | |
220 #ifdef FEAT_MOUSE | |
221 /* When dragging with the mouse, don't scroll that quickly */ | |
1121 | 222 if (mouse_dragging > 0) |
7 | 223 p_so = mouse_dragging - 1; |
224 #endif | |
225 | |
226 old_topline = curwin->w_topline; | |
227 #ifdef FEAT_DIFF | |
228 old_topfill = curwin->w_topfill; | |
229 #endif | |
230 | |
231 /* | |
232 * If the buffer is empty, always set topline to 1. | |
233 */ | |
11121
778c10516955
patch 8.0.0448: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents:
10607
diff
changeset
|
234 if (BUFEMPTY()) /* special case - file is empty */ |
7 | 235 { |
236 if (curwin->w_topline != 1) | |
237 redraw_later(NOT_VALID); | |
238 curwin->w_topline = 1; | |
239 curwin->w_botline = 2; | |
240 curwin->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP; | |
241 curwin->w_scbind_pos = 1; | |
242 } | |
243 | |
244 /* | |
245 * If the cursor is above or near the top of the window, scroll the window | |
246 * to show the line the cursor is in, with 'scrolloff' context. | |
247 */ | |
248 else | |
249 { | |
250 if (curwin->w_topline > 1) | |
251 { | |
252 /* If the cursor is above topline, scrolling is always needed. | |
253 * If the cursor is far below topline and there is no folding, | |
254 * scrolling down is never needed. */ | |
255 if (curwin->w_cursor.lnum < curwin->w_topline) | |
256 check_topline = TRUE; | |
257 else if (check_top_offset()) | |
258 check_topline = TRUE; | |
259 } | |
260 #ifdef FEAT_DIFF | |
261 /* Check if there are more filler lines than allowed. */ | |
262 if (!check_topline && curwin->w_topfill > diff_check_fill(curwin, | |
263 curwin->w_topline)) | |
264 check_topline = TRUE; | |
265 #endif | |
266 | |
267 if (check_topline) | |
268 { | |
269 halfheight = curwin->w_height / 2 - 1; | |
270 if (halfheight < 2) | |
271 halfheight = 2; | |
272 | |
273 #ifdef FEAT_FOLDING | |
274 if (hasAnyFolding(curwin)) | |
275 { | |
276 /* Count the number of logical lines between the cursor and | |
277 * topline + p_so (approximation of how much will be | |
278 * scrolled). */ | |
279 n = 0; | |
280 for (lnum = curwin->w_cursor.lnum; | |
281 lnum < curwin->w_topline + p_so; ++lnum) | |
282 { | |
283 ++n; | |
284 /* stop at end of file or when we know we are far off */ | |
285 if (lnum >= curbuf->b_ml.ml_line_count || n >= halfheight) | |
286 break; | |
287 (void)hasFolding(lnum, NULL, &lnum); | |
288 } | |
289 } | |
290 else | |
291 #endif | |
292 n = curwin->w_topline + p_so - curwin->w_cursor.lnum; | |
293 | |
294 /* If we weren't very close to begin with, we scroll to put the | |
295 * cursor in the middle of the window. Otherwise put the cursor | |
296 * near the top of the window. */ | |
297 if (n >= halfheight) | |
298 scroll_cursor_halfway(FALSE); | |
299 else | |
300 { | |
532 | 301 scroll_cursor_top(scrolljump_value(), FALSE); |
7 | 302 check_botline = TRUE; |
303 } | |
304 } | |
305 | |
306 else | |
307 { | |
308 #ifdef FEAT_FOLDING | |
309 /* Make sure topline is the first line of a fold. */ | |
310 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); | |
311 #endif | |
312 check_botline = TRUE; | |
313 } | |
314 } | |
315 | |
316 /* | |
317 * If the cursor is below the bottom of the window, scroll the window | |
318 * to put the cursor on the window. | |
319 * When w_botline is invalid, recompute it first, to avoid a redraw later. | |
320 * If w_botline was approximated, we might need a redraw later in a few | |
321 * cases, but we don't want to spend (a lot of) time recomputing w_botline | |
322 * for every small change. | |
323 */ | |
324 if (check_botline) | |
325 { | |
326 if (!(curwin->w_valid & VALID_BOTLINE_AP)) | |
327 validate_botline(); | |
328 | |
329 if (curwin->w_botline <= curbuf->b_ml.ml_line_count) | |
330 { | |
1744 | 331 if (curwin->w_cursor.lnum < curwin->w_botline) |
332 { | |
333 if (((long)curwin->w_cursor.lnum | |
7 | 334 >= (long)curwin->w_botline - p_so |
335 #ifdef FEAT_FOLDING | |
336 || hasAnyFolding(curwin) | |
337 #endif | |
338 )) | |
1744 | 339 { |
7 | 340 lineoff_T loff; |
341 | |
1744 | 342 /* Cursor is (a few lines) above botline, check if there are |
343 * 'scrolloff' window lines below the cursor. If not, need to | |
344 * scroll. */ | |
7 | 345 n = curwin->w_empty_rows; |
346 loff.lnum = curwin->w_cursor.lnum; | |
347 #ifdef FEAT_FOLDING | |
348 /* In a fold go to its last line. */ | |
349 (void)hasFolding(loff.lnum, NULL, &loff.lnum); | |
350 #endif | |
351 #ifdef FEAT_DIFF | |
352 loff.fill = 0; | |
353 n += curwin->w_filler_rows; | |
354 #endif | |
355 loff.height = 0; | |
356 while (loff.lnum < curwin->w_botline | |
357 #ifdef FEAT_DIFF | |
358 && (loff.lnum + 1 < curwin->w_botline || loff.fill == 0) | |
359 #endif | |
360 ) | |
361 { | |
362 n += loff.height; | |
363 if (n >= p_so) | |
364 break; | |
365 botline_forw(&loff); | |
366 } | |
367 if (n >= p_so) | |
368 /* sufficient context, no need to scroll */ | |
369 check_botline = FALSE; | |
1744 | 370 } |
371 else | |
372 /* sufficient context, no need to scroll */ | |
373 check_botline = FALSE; | |
7 | 374 } |
375 if (check_botline) | |
376 { | |
377 #ifdef FEAT_FOLDING | |
378 if (hasAnyFolding(curwin)) | |
379 { | |
380 /* Count the number of logical lines between the cursor and | |
381 * botline - p_so (approximation of how much will be | |
382 * scrolled). */ | |
383 line_count = 0; | |
384 for (lnum = curwin->w_cursor.lnum; | |
385 lnum >= curwin->w_botline - p_so; --lnum) | |
386 { | |
387 ++line_count; | |
388 /* stop at end of file or when we know we are far off */ | |
389 if (lnum <= 0 || line_count > curwin->w_height + 1) | |
390 break; | |
391 (void)hasFolding(lnum, &lnum, NULL); | |
392 } | |
393 } | |
394 else | |
395 #endif | |
396 line_count = curwin->w_cursor.lnum - curwin->w_botline | |
397 + 1 + p_so; | |
398 if (line_count <= curwin->w_height + 1) | |
532 | 399 scroll_cursor_bot(scrolljump_value(), FALSE); |
7 | 400 else |
401 scroll_cursor_halfway(FALSE); | |
402 } | |
403 } | |
404 } | |
405 curwin->w_valid |= VALID_TOPLINE; | |
406 | |
407 /* | |
408 * Need to redraw when topline changed. | |
409 */ | |
410 if (curwin->w_topline != old_topline | |
411 #ifdef FEAT_DIFF | |
412 || curwin->w_topfill != old_topfill | |
413 #endif | |
414 ) | |
415 { | |
3318 | 416 dollar_vcol = -1; |
740 | 417 if (curwin->w_skipcol != 0) |
7 | 418 { |
419 curwin->w_skipcol = 0; | |
420 redraw_later(NOT_VALID); | |
421 } | |
422 else | |
423 redraw_later(VALID); | |
424 /* May need to set w_skipcol when cursor in w_topline. */ | |
425 if (curwin->w_cursor.lnum == curwin->w_topline) | |
426 validate_cursor(); | |
427 } | |
428 | |
429 #ifdef FEAT_MOUSE | |
430 p_so = save_so; | |
431 #endif | |
432 } | |
433 | |
434 /* | |
532 | 435 * Return the scrolljump value to use for the current window. |
436 * When 'scrolljump' is positive use it as-is. | |
437 * When 'scrolljump' is negative use it as a percentage of the window height. | |
438 */ | |
439 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
440 scrolljump_value(void) |
532 | 441 { |
442 if (p_sj >= 0) | |
443 return (int)p_sj; | |
444 return (curwin->w_height * -p_sj) / 100; | |
445 } | |
446 | |
447 /* | |
7 | 448 * Return TRUE when there are not 'scrolloff' lines above the cursor for the |
449 * current window. | |
450 */ | |
451 static int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
452 check_top_offset(void) |
7 | 453 { |
454 lineoff_T loff; | |
455 int n; | |
456 | |
457 if (curwin->w_cursor.lnum < curwin->w_topline + p_so | |
458 #ifdef FEAT_FOLDING | |
459 || hasAnyFolding(curwin) | |
460 #endif | |
461 ) | |
462 { | |
463 loff.lnum = curwin->w_cursor.lnum; | |
464 #ifdef FEAT_DIFF | |
465 loff.fill = 0; | |
466 n = curwin->w_topfill; /* always have this context */ | |
467 #else | |
468 n = 0; | |
469 #endif | |
470 /* Count the visible screen lines above the cursor line. */ | |
471 while (n < p_so) | |
472 { | |
473 topline_back(&loff); | |
474 /* Stop when included a line above the window. */ | |
475 if (loff.lnum < curwin->w_topline | |
476 #ifdef FEAT_DIFF | |
477 || (loff.lnum == curwin->w_topline && loff.fill > 0) | |
478 #endif | |
479 ) | |
480 break; | |
481 n += loff.height; | |
482 } | |
483 if (n < p_so) | |
484 return TRUE; | |
485 } | |
486 return FALSE; | |
487 } | |
488 | |
489 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
490 update_curswant(void) |
7 | 491 { |
492 if (curwin->w_set_curswant) | |
493 { | |
494 validate_virtcol(); | |
495 curwin->w_curswant = curwin->w_virtcol; | |
496 curwin->w_set_curswant = FALSE; | |
497 } | |
498 } | |
499 | |
500 /* | |
501 * Check if the cursor has moved. Set the w_valid flag accordingly. | |
502 */ | |
503 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
504 check_cursor_moved(win_T *wp) |
7 | 505 { |
506 if (wp->w_cursor.lnum != wp->w_valid_cursor.lnum) | |
507 { | |
508 wp->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL | |
509 |VALID_CHEIGHT|VALID_CROW|VALID_TOPLINE); | |
510 wp->w_valid_cursor = wp->w_cursor; | |
511 wp->w_valid_leftcol = wp->w_leftcol; | |
512 } | |
513 else if (wp->w_cursor.col != wp->w_valid_cursor.col | |
514 || wp->w_leftcol != wp->w_valid_leftcol | |
515 #ifdef FEAT_VIRTUALEDIT | |
516 || wp->w_cursor.coladd != wp->w_valid_cursor.coladd | |
517 #endif | |
518 ) | |
519 { | |
520 wp->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL); | |
521 wp->w_valid_cursor.col = wp->w_cursor.col; | |
522 wp->w_valid_leftcol = wp->w_leftcol; | |
523 #ifdef FEAT_VIRTUALEDIT | |
524 wp->w_valid_cursor.coladd = wp->w_cursor.coladd; | |
525 #endif | |
526 } | |
527 } | |
528 | |
529 /* | |
530 * Call this function when some window settings have changed, which require | |
531 * the cursor position, botline and topline to be recomputed and the window to | |
532 * be redrawn. E.g, when changing the 'wrap' option or folding. | |
533 */ | |
534 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
535 changed_window_setting(void) |
7 | 536 { |
537 changed_window_setting_win(curwin); | |
538 } | |
539 | |
540 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
541 changed_window_setting_win(win_T *wp) |
7 | 542 { |
543 wp->w_lines_valid = 0; | |
544 changed_line_abv_curs_win(wp); | |
545 wp->w_valid &= ~(VALID_BOTLINE|VALID_BOTLINE_AP|VALID_TOPLINE); | |
546 redraw_win_later(wp, NOT_VALID); | |
547 } | |
548 | |
549 /* | |
550 * Set wp->w_topline to a certain number. | |
551 */ | |
552 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
553 set_topline(win_T *wp, linenr_T lnum) |
7 | 554 { |
555 #ifdef FEAT_FOLDING | |
556 /* go to first of folded lines */ | |
557 (void)hasFoldingWin(wp, lnum, &lnum, NULL, TRUE, NULL); | |
558 #endif | |
559 /* Approximate the value of w_botline */ | |
560 wp->w_botline += lnum - wp->w_topline; | |
561 wp->w_topline = lnum; | |
1744 | 562 wp->w_topline_was_set = TRUE; |
7 | 563 #ifdef FEAT_DIFF |
564 wp->w_topfill = 0; | |
565 #endif | |
566 wp->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_TOPLINE); | |
567 /* Don't set VALID_TOPLINE here, 'scrolloff' needs to be checked. */ | |
568 redraw_later(VALID); | |
569 } | |
570 | |
571 /* | |
572 * Call this function when the length of the cursor line (in screen | |
573 * characters) has changed, and the change is before the cursor. | |
574 * Need to take care of w_botline separately! | |
575 */ | |
576 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
577 changed_cline_bef_curs(void) |
7 | 578 { |
579 curwin->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL | |
580 |VALID_CHEIGHT|VALID_TOPLINE); | |
581 } | |
582 | |
583 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
584 changed_cline_bef_curs_win(win_T *wp) |
7 | 585 { |
586 wp->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL | |
587 |VALID_CHEIGHT|VALID_TOPLINE); | |
588 } | |
589 | |
590 /* | |
591 * Call this function when the length of a line (in screen characters) above | |
592 * the cursor have changed. | |
593 * Need to take care of w_botline separately! | |
594 */ | |
595 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
596 changed_line_abv_curs(void) |
7 | 597 { |
598 curwin->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL|VALID_CROW | |
599 |VALID_CHEIGHT|VALID_TOPLINE); | |
600 } | |
601 | |
602 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
603 changed_line_abv_curs_win(win_T *wp) |
7 | 604 { |
605 wp->w_valid &= ~(VALID_WROW|VALID_WCOL|VALID_VIRTCOL|VALID_CROW | |
606 |VALID_CHEIGHT|VALID_TOPLINE); | |
607 } | |
608 | |
609 /* | |
610 * Make sure the value of curwin->w_botline is valid. | |
611 */ | |
612 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
613 validate_botline(void) |
7 | 614 { |
615 if (!(curwin->w_valid & VALID_BOTLINE)) | |
616 comp_botline(curwin); | |
617 } | |
618 | |
619 /* | |
620 * Mark curwin->w_botline as invalid (because of some change in the buffer). | |
621 */ | |
622 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
623 invalidate_botline(void) |
7 | 624 { |
625 curwin->w_valid &= ~(VALID_BOTLINE|VALID_BOTLINE_AP); | |
626 } | |
627 | |
628 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
629 invalidate_botline_win(win_T *wp) |
7 | 630 { |
631 wp->w_valid &= ~(VALID_BOTLINE|VALID_BOTLINE_AP); | |
632 } | |
633 | |
634 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
635 approximate_botline_win( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
636 win_T *wp) |
7 | 637 { |
638 wp->w_valid &= ~VALID_BOTLINE; | |
639 } | |
640 | |
641 /* | |
642 * Return TRUE if curwin->w_wrow and curwin->w_wcol are valid. | |
643 */ | |
644 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
645 cursor_valid(void) |
7 | 646 { |
647 check_cursor_moved(curwin); | |
648 return ((curwin->w_valid & (VALID_WROW|VALID_WCOL)) == | |
649 (VALID_WROW|VALID_WCOL)); | |
650 } | |
651 | |
652 /* | |
653 * Validate cursor position. Makes sure w_wrow and w_wcol are valid. | |
654 * w_topline must be valid, you may need to call update_topline() first! | |
655 */ | |
656 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
657 validate_cursor(void) |
7 | 658 { |
659 check_cursor_moved(curwin); | |
660 if ((curwin->w_valid & (VALID_WCOL|VALID_WROW)) != (VALID_WCOL|VALID_WROW)) | |
661 curs_columns(TRUE); | |
662 } | |
663 | |
664 #if defined(FEAT_GUI) || defined(PROTO) | |
665 /* | |
666 * validate w_cline_row. | |
667 */ | |
668 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
669 validate_cline_row(void) |
7 | 670 { |
671 /* | |
672 * First make sure that w_topline is valid (after moving the cursor). | |
673 */ | |
674 update_topline(); | |
675 check_cursor_moved(curwin); | |
676 if (!(curwin->w_valid & VALID_CROW)) | |
6441 | 677 curs_rows(curwin); |
7 | 678 } |
679 #endif | |
680 | |
681 /* | |
682 * Compute wp->w_cline_row and wp->w_cline_height, based on the current value | |
2154
7c8c7c95a865
First step in the Vim 7.3 branch. Changed version numbers.
Bram Moolenaar <bram@zimbu.org>
parents:
2082
diff
changeset
|
683 * of wp->w_topline. |
7 | 684 */ |
685 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
686 curs_rows(win_T *wp) |
7 | 687 { |
688 linenr_T lnum; | |
689 int i; | |
690 int all_invalid; | |
691 int valid; | |
692 #ifdef FEAT_FOLDING | |
693 long fold_count; | |
694 #endif | |
695 | |
696 /* Check if wp->w_lines[].wl_size is invalid */ | |
697 all_invalid = (!redrawing() | |
698 || wp->w_lines_valid == 0 | |
699 || wp->w_lines[0].wl_lnum > wp->w_topline); | |
700 i = 0; | |
701 wp->w_cline_row = 0; | |
702 for (lnum = wp->w_topline; lnum < wp->w_cursor.lnum; ++i) | |
703 { | |
704 valid = FALSE; | |
705 if (!all_invalid && i < wp->w_lines_valid) | |
706 { | |
707 if (wp->w_lines[i].wl_lnum < lnum || !wp->w_lines[i].wl_valid) | |
708 continue; /* skip changed or deleted lines */ | |
709 if (wp->w_lines[i].wl_lnum == lnum) | |
710 { | |
711 #ifdef FEAT_FOLDING | |
712 /* Check for newly inserted lines below this row, in which | |
713 * case we need to check for folded lines. */ | |
714 if (!wp->w_buffer->b_mod_set | |
715 || wp->w_lines[i].wl_lastlnum < wp->w_cursor.lnum | |
716 || wp->w_buffer->b_mod_top | |
717 > wp->w_lines[i].wl_lastlnum + 1) | |
718 #endif | |
719 valid = TRUE; | |
720 } | |
721 else if (wp->w_lines[i].wl_lnum > lnum) | |
722 --i; /* hold at inserted lines */ | |
723 } | |
724 if (valid | |
725 #ifdef FEAT_DIFF | |
726 && (lnum != wp->w_topline || !wp->w_p_diff) | |
727 #endif | |
728 ) | |
729 { | |
730 #ifdef FEAT_FOLDING | |
731 lnum = wp->w_lines[i].wl_lastlnum + 1; | |
732 /* Cursor inside folded lines, don't count this row */ | |
733 if (lnum > wp->w_cursor.lnum) | |
734 break; | |
735 #else | |
736 ++lnum; | |
737 #endif | |
738 wp->w_cline_row += wp->w_lines[i].wl_size; | |
739 } | |
740 else | |
741 { | |
742 #ifdef FEAT_FOLDING | |
743 fold_count = foldedCount(wp, lnum, NULL); | |
744 if (fold_count) | |
745 { | |
746 lnum += fold_count; | |
747 if (lnum > wp->w_cursor.lnum) | |
748 break; | |
749 ++wp->w_cline_row; | |
750 } | |
751 else | |
752 #endif | |
753 #ifdef FEAT_DIFF | |
754 if (lnum == wp->w_topline) | |
755 wp->w_cline_row += plines_win_nofill(wp, lnum++, TRUE) | |
756 + wp->w_topfill; | |
757 else | |
758 #endif | |
759 wp->w_cline_row += plines_win(wp, lnum++, TRUE); | |
760 } | |
761 } | |
762 | |
763 check_cursor_moved(wp); | |
764 if (!(wp->w_valid & VALID_CHEIGHT)) | |
765 { | |
766 if (all_invalid | |
767 || i == wp->w_lines_valid | |
768 || (i < wp->w_lines_valid | |
769 && (!wp->w_lines[i].wl_valid | |
770 || wp->w_lines[i].wl_lnum != wp->w_cursor.lnum))) | |
771 { | |
772 #ifdef FEAT_DIFF | |
773 if (wp->w_cursor.lnum == wp->w_topline) | |
774 wp->w_cline_height = plines_win_nofill(wp, wp->w_cursor.lnum, | |
775 TRUE) + wp->w_topfill; | |
776 else | |
777 #endif | |
778 wp->w_cline_height = plines_win(wp, wp->w_cursor.lnum, TRUE); | |
779 #ifdef FEAT_FOLDING | |
780 wp->w_cline_folded = hasFoldingWin(wp, wp->w_cursor.lnum, | |
781 NULL, NULL, TRUE, NULL); | |
782 #endif | |
783 } | |
784 else if (i > wp->w_lines_valid) | |
785 { | |
786 /* a line that is too long to fit on the last screen line */ | |
787 wp->w_cline_height = 0; | |
788 #ifdef FEAT_FOLDING | |
789 wp->w_cline_folded = hasFoldingWin(wp, wp->w_cursor.lnum, | |
790 NULL, NULL, TRUE, NULL); | |
791 #endif | |
792 } | |
793 else | |
794 { | |
795 wp->w_cline_height = wp->w_lines[i].wl_size; | |
796 #ifdef FEAT_FOLDING | |
797 wp->w_cline_folded = wp->w_lines[i].wl_folded; | |
798 #endif | |
799 } | |
800 } | |
801 | |
5764 | 802 redraw_for_cursorline(curwin); |
7 | 803 wp->w_valid |= VALID_CROW|VALID_CHEIGHT; |
804 | |
805 } | |
806 | |
807 /* | |
808 * Validate curwin->w_virtcol only. | |
809 */ | |
810 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
811 validate_virtcol(void) |
7 | 812 { |
813 validate_virtcol_win(curwin); | |
814 } | |
815 | |
816 /* | |
817 * Validate wp->w_virtcol only. | |
818 */ | |
819 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
820 validate_virtcol_win(win_T *wp) |
7 | 821 { |
822 check_cursor_moved(wp); | |
823 if (!(wp->w_valid & VALID_VIRTCOL)) | |
824 { | |
825 getvvcol(wp, &wp->w_cursor, NULL, &(wp->w_virtcol), NULL); | |
826 wp->w_valid |= VALID_VIRTCOL; | |
740 | 827 #ifdef FEAT_SYN_HL |
752 | 828 if (wp->w_p_cuc |
829 # ifdef FEAT_INS_EXPAND | |
830 && !pum_visible() | |
831 # endif | |
832 ) | |
740 | 833 redraw_win_later(wp, SOME_VALID); |
834 #endif | |
7 | 835 } |
836 } | |
837 | |
838 /* | |
839 * Validate curwin->w_cline_height only. | |
840 */ | |
841 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
842 validate_cheight(void) |
7 | 843 { |
844 check_cursor_moved(curwin); | |
845 if (!(curwin->w_valid & VALID_CHEIGHT)) | |
846 { | |
847 #ifdef FEAT_DIFF | |
848 if (curwin->w_cursor.lnum == curwin->w_topline) | |
849 curwin->w_cline_height = plines_nofill(curwin->w_cursor.lnum) | |
850 + curwin->w_topfill; | |
851 else | |
852 #endif | |
853 curwin->w_cline_height = plines(curwin->w_cursor.lnum); | |
854 #ifdef FEAT_FOLDING | |
855 curwin->w_cline_folded = hasFolding(curwin->w_cursor.lnum, NULL, NULL); | |
856 #endif | |
857 curwin->w_valid |= VALID_CHEIGHT; | |
858 } | |
859 } | |
860 | |
861 /* | |
1668 | 862 * Validate w_wcol and w_virtcol only. |
7 | 863 */ |
864 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
865 validate_cursor_col(void) |
7 | 866 { |
867 colnr_T off; | |
868 colnr_T col; | |
2070
4483ee552619
updated for version 7.2.355
Bram Moolenaar <bram@zimbu.org>
parents:
1980
diff
changeset
|
869 int width; |
7 | 870 |
871 validate_virtcol(); | |
872 if (!(curwin->w_valid & VALID_WCOL)) | |
873 { | |
874 col = curwin->w_virtcol; | |
875 off = curwin_col_off(); | |
876 col += off; | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
877 width = curwin->w_width - off + curwin_col_off2(); |
7 | 878 |
879 /* long line wrapping, adjust curwin->w_wrow */ | |
1668 | 880 if (curwin->w_p_wrap |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
881 && col >= (colnr_T)curwin->w_width |
2070
4483ee552619
updated for version 7.2.355
Bram Moolenaar <bram@zimbu.org>
parents:
1980
diff
changeset
|
882 && width > 0) |
4483ee552619
updated for version 7.2.355
Bram Moolenaar <bram@zimbu.org>
parents:
1980
diff
changeset
|
883 /* use same formula as what is used in curs_columns() */ |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
884 col -= ((col - curwin->w_width) / width + 1) * width; |
1668 | 885 if (col > (int)curwin->w_leftcol) |
886 col -= curwin->w_leftcol; | |
887 else | |
888 col = 0; | |
7 | 889 curwin->w_wcol = col; |
1668 | 890 |
7 | 891 curwin->w_valid |= VALID_WCOL; |
892 } | |
893 } | |
894 | |
895 /* | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
896 * Compute offset of a window, occupied by absolute or relative line number, |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
897 * fold column and sign column (these don't move when scrolling horizontally). |
7 | 898 */ |
899 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
900 win_col_off(win_T *wp) |
7 | 901 { |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
902 return (((wp->w_p_nu || wp->w_p_rnu) ? number_width(wp) + 1 : 0) |
7 | 903 #ifdef FEAT_CMDWIN |
904 + (cmdwin_type == 0 || wp != curwin ? 0 : 1) | |
905 #endif | |
906 #ifdef FEAT_FOLDING | |
907 + wp->w_p_fdc | |
908 #endif | |
909 #ifdef FEAT_SIGNS | |
9852
4eea48b76d03
commit https://github.com/vim/vim/commit/95ec9d6a6ab3117d60ff638670a803d43974ba51
Christian Brabandt <cb@256bit.org>
parents:
9649
diff
changeset
|
910 + (signcolumn_on(wp) ? 2 : 0) |
7 | 911 #endif |
912 ); | |
913 } | |
914 | |
915 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
916 curwin_col_off(void) |
7 | 917 { |
918 return win_col_off(curwin); | |
919 } | |
920 | |
921 /* | |
922 * Return the difference in column offset for the second screen line of a | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
923 * wrapped line. It's 8 if 'number' or 'relativenumber' is on and 'n' is in |
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
924 * 'cpoptions'. |
7 | 925 */ |
926 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
927 win_col_off2(win_T *wp) |
7 | 928 { |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
929 if ((wp->w_p_nu || wp->w_p_rnu) && vim_strchr(p_cpo, CPO_NUMCOL) != NULL) |
13 | 930 return number_width(wp) + 1; |
7 | 931 return 0; |
932 } | |
933 | |
934 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
935 curwin_col_off2(void) |
7 | 936 { |
937 return win_col_off2(curwin); | |
938 } | |
939 | |
940 /* | |
941 * compute curwin->w_wcol and curwin->w_virtcol. | |
942 * Also updates curwin->w_wrow and curwin->w_cline_row. | |
943 * Also updates curwin->w_leftcol. | |
944 */ | |
945 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
946 curs_columns( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
947 int may_scroll) /* when TRUE, may scroll horizontally */ |
7 | 948 { |
949 int diff; | |
950 int extra; /* offset for first screen line */ | |
951 int off_left, off_right; | |
952 int n; | |
953 int p_lines; | |
954 int width = 0; | |
955 int textwidth; | |
956 int new_leftcol; | |
957 colnr_T startcol; | |
958 colnr_T endcol; | |
959 colnr_T prev_skipcol; | |
960 | |
961 /* | |
962 * First make sure that w_topline is valid (after moving the cursor). | |
963 */ | |
964 update_topline(); | |
965 | |
966 /* | |
967 * Next make sure that w_cline_row is valid. | |
968 */ | |
969 if (!(curwin->w_valid & VALID_CROW)) | |
6441 | 970 curs_rows(curwin); |
7 | 971 |
972 /* | |
973 * Compute the number of virtual columns. | |
974 */ | |
975 #ifdef FEAT_FOLDING | |
976 if (curwin->w_cline_folded) | |
977 /* In a folded line the cursor is always in the first column */ | |
978 startcol = curwin->w_virtcol = endcol = curwin->w_leftcol; | |
979 else | |
980 #endif | |
981 getvvcol(curwin, &curwin->w_cursor, | |
982 &startcol, &(curwin->w_virtcol), &endcol); | |
983 | |
984 /* remove '$' from change command when cursor moves onto it */ | |
985 if (startcol > dollar_vcol) | |
3318 | 986 dollar_vcol = -1; |
7 | 987 |
988 extra = curwin_col_off(); | |
989 curwin->w_wcol = curwin->w_virtcol + extra; | |
990 endcol += extra; | |
991 | |
992 /* | |
993 * Now compute w_wrow, counting screen lines from w_cline_row. | |
994 */ | |
995 curwin->w_wrow = curwin->w_cline_row; | |
996 | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
997 textwidth = curwin->w_width - extra; |
7 | 998 if (textwidth <= 0) |
999 { | |
1000 /* No room for text, put cursor in last char of window. */ | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
1001 curwin->w_wcol = curwin->w_width - 1; |
7 | 1002 curwin->w_wrow = curwin->w_height - 1; |
1003 } | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12152
diff
changeset
|
1004 else if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 1005 { |
1006 width = textwidth + curwin_col_off2(); | |
1007 | |
1008 /* long line wrapping, adjust curwin->w_wrow */ | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
1009 if (curwin->w_wcol >= curwin->w_width) |
7 | 1010 { |
2070
4483ee552619
updated for version 7.2.355
Bram Moolenaar <bram@zimbu.org>
parents:
1980
diff
changeset
|
1011 /* this same formula is used in validate_cursor_col() */ |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
1012 n = (curwin->w_wcol - curwin->w_width) / width + 1; |
7 | 1013 curwin->w_wcol -= n * width; |
1014 curwin->w_wrow += n; | |
1015 | |
1016 #ifdef FEAT_LINEBREAK | |
1017 /* When cursor wraps to first char of next line in Insert | |
1018 * mode, the 'showbreak' string isn't shown, backup to first | |
1019 * column */ | |
1020 if (*p_sbr && *ml_get_cursor() == NUL | |
1021 && curwin->w_wcol == (int)vim_strsize(p_sbr)) | |
1022 curwin->w_wcol = 0; | |
1023 #endif | |
1024 } | |
1025 } | |
1026 | |
1027 /* No line wrapping: compute curwin->w_leftcol if scrolling is on and line | |
1028 * is not folded. | |
1029 * If scrolling is off, curwin->w_leftcol is assumed to be 0 */ | |
3263 | 1030 else if (may_scroll |
7 | 1031 #ifdef FEAT_FOLDING |
1032 && !curwin->w_cline_folded | |
1033 #endif | |
1034 ) | |
1035 { | |
1036 /* | |
1037 * If Cursor is left of the screen, scroll rightwards. | |
1038 * If Cursor is right of the screen, scroll leftwards | |
1039 * If we get closer to the edge than 'sidescrolloff', scroll a little | |
1040 * extra | |
1041 */ | |
1042 off_left = (int)startcol - (int)curwin->w_leftcol - p_siso; | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
1043 off_right = (int)endcol - (int)(curwin->w_leftcol + curwin->w_width |
7 | 1044 - p_siso) + 1; |
1045 if (off_left < 0 || off_right > 0) | |
1046 { | |
1047 if (off_left < 0) | |
1048 diff = -off_left; | |
1049 else | |
1050 diff = off_right; | |
1051 | |
1052 /* When far off or not enough room on either side, put cursor in | |
1053 * middle of window. */ | |
1054 if (p_ss == 0 || diff >= textwidth / 2 || off_right >= off_left) | |
1055 new_leftcol = curwin->w_wcol - extra - textwidth / 2; | |
1056 else | |
1057 { | |
1058 if (diff < p_ss) | |
1059 diff = p_ss; | |
1060 if (off_left < 0) | |
1061 new_leftcol = curwin->w_leftcol - diff; | |
1062 else | |
1063 new_leftcol = curwin->w_leftcol + diff; | |
1064 } | |
1065 if (new_leftcol < 0) | |
1066 new_leftcol = 0; | |
1067 if (new_leftcol != (int)curwin->w_leftcol) | |
1068 { | |
1069 curwin->w_leftcol = new_leftcol; | |
1070 /* screen has to be redrawn with new curwin->w_leftcol */ | |
1071 redraw_later(NOT_VALID); | |
1072 } | |
1073 } | |
1074 curwin->w_wcol -= curwin->w_leftcol; | |
1075 } | |
1076 else if (curwin->w_wcol > (int)curwin->w_leftcol) | |
1077 curwin->w_wcol -= curwin->w_leftcol; | |
1078 else | |
1079 curwin->w_wcol = 0; | |
1080 | |
1081 #ifdef FEAT_DIFF | |
1082 /* Skip over filler lines. At the top use w_topfill, there | |
1083 * may be some filler lines above the window. */ | |
1084 if (curwin->w_cursor.lnum == curwin->w_topline) | |
1085 curwin->w_wrow += curwin->w_topfill; | |
1086 else | |
1087 curwin->w_wrow += diff_check_fill(curwin, curwin->w_cursor.lnum); | |
1088 #endif | |
1089 | |
1090 prev_skipcol = curwin->w_skipcol; | |
1091 | |
1092 p_lines = 0; | |
1093 if ((curwin->w_wrow >= curwin->w_height | |
1094 || ((prev_skipcol > 0 | |
1095 || curwin->w_wrow + p_so >= curwin->w_height) | |
1096 && (p_lines = | |
1097 #ifdef FEAT_DIFF | |
1098 plines_win_nofill | |
1099 #else | |
1100 plines_win | |
1101 #endif | |
1102 (curwin, curwin->w_cursor.lnum, FALSE)) | |
1103 - 1 >= curwin->w_height)) | |
1104 && curwin->w_height != 0 | |
1105 && curwin->w_cursor.lnum == curwin->w_topline | |
1106 && width > 0 | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12152
diff
changeset
|
1107 && curwin->w_width != 0) |
7 | 1108 { |
1109 /* Cursor past end of screen. Happens with a single line that does | |
1110 * not fit on screen. Find a skipcol to show the text around the | |
1111 * cursor. Avoid scrolling all the time. compute value of "extra": | |
1112 * 1: Less than "p_so" lines above | |
1113 * 2: Less than "p_so" lines below | |
1114 * 3: both of them */ | |
1115 extra = 0; | |
1116 if (curwin->w_skipcol + p_so * width > curwin->w_virtcol) | |
1117 extra = 1; | |
1118 /* Compute last display line of the buffer line that we want at the | |
1119 * bottom of the window. */ | |
1120 if (p_lines == 0) | |
1121 p_lines = plines_win(curwin, curwin->w_cursor.lnum, FALSE); | |
1122 --p_lines; | |
1123 if (p_lines > curwin->w_wrow + p_so) | |
1124 n = curwin->w_wrow + p_so; | |
1125 else | |
1126 n = p_lines; | |
1127 if ((colnr_T)n >= curwin->w_height + curwin->w_skipcol / width) | |
1128 extra += 2; | |
1129 | |
1130 if (extra == 3 || p_lines < p_so * 2) | |
1131 { | |
1132 /* not enough room for 'scrolloff', put cursor in the middle */ | |
1133 n = curwin->w_virtcol / width; | |
1134 if (n > curwin->w_height / 2) | |
1135 n -= curwin->w_height / 2; | |
1136 else | |
1137 n = 0; | |
1138 /* don't skip more than necessary */ | |
1139 if (n > p_lines - curwin->w_height + 1) | |
1140 n = p_lines - curwin->w_height + 1; | |
1141 curwin->w_skipcol = n * width; | |
1142 } | |
1143 else if (extra == 1) | |
1144 { | |
1145 /* less then 'scrolloff' lines above, decrease skipcol */ | |
1146 extra = (curwin->w_skipcol + p_so * width - curwin->w_virtcol | |
1147 + width - 1) / width; | |
1148 if (extra > 0) | |
1149 { | |
1150 if ((colnr_T)(extra * width) > curwin->w_skipcol) | |
1151 extra = curwin->w_skipcol / width; | |
1152 curwin->w_skipcol -= extra * width; | |
1153 } | |
1154 } | |
1155 else if (extra == 2) | |
1156 { | |
1157 /* less then 'scrolloff' lines below, increase skipcol */ | |
1158 endcol = (n - curwin->w_height + 1) * width; | |
1159 while (endcol > curwin->w_virtcol) | |
1160 endcol -= width; | |
1161 if (endcol > curwin->w_skipcol) | |
1162 curwin->w_skipcol = endcol; | |
1163 } | |
1164 | |
1165 curwin->w_wrow -= curwin->w_skipcol / width; | |
1166 if (curwin->w_wrow >= curwin->w_height) | |
1167 { | |
1168 /* small window, make sure cursor is in it */ | |
1169 extra = curwin->w_wrow - curwin->w_height + 1; | |
1170 curwin->w_skipcol += extra * width; | |
1171 curwin->w_wrow -= extra; | |
1172 } | |
1173 | |
1174 extra = ((int)prev_skipcol - (int)curwin->w_skipcol) / width; | |
1175 if (extra > 0) | |
1176 win_ins_lines(curwin, 0, extra, FALSE, FALSE); | |
1177 else if (extra < 0) | |
12152
69af108df70e
patch 8.0.0956: scrolling in a terminal window has flicker
Christian Brabandt <cb@256bit.org>
parents:
11258
diff
changeset
|
1178 win_del_lines(curwin, 0, -extra, FALSE, FALSE, 0); |
7 | 1179 } |
1180 else | |
1181 curwin->w_skipcol = 0; | |
1182 if (prev_skipcol != curwin->w_skipcol) | |
1183 redraw_later(NOT_VALID); | |
1184 | |
740 | 1185 #ifdef FEAT_SYN_HL |
5749 | 1186 /* Redraw when w_virtcol changes and 'cursorcolumn' is set */ |
1187 if (curwin->w_p_cuc && (curwin->w_valid & VALID_VIRTCOL) == 0 | |
1188 # ifdef FEAT_INS_EXPAND | |
1189 && !pum_visible() | |
1190 # endif | |
1191 ) | |
1192 redraw_later(SOME_VALID); | |
2178
c6f1aa1e9f32
Add 'relativenumber' patch from Markus Heidelberg.
Bram Moolenaar <bram@vim.org>
parents:
2154
diff
changeset
|
1193 #endif |
740 | 1194 |
7 | 1195 curwin->w_valid |= VALID_WCOL|VALID_WROW|VALID_VIRTCOL; |
1196 } | |
1197 | |
1198 /* | |
1199 * Scroll the current window down by "line_count" logical lines. "CTRL-Y" | |
1200 */ | |
1201 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1202 scrolldown( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1203 long line_count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1204 int byfold UNUSED) /* TRUE: count a closed fold as one line */ |
7 | 1205 { |
1206 long done = 0; /* total # of physical lines done */ | |
1207 int wrow; | |
1208 int moved = FALSE; | |
1209 | |
1210 #ifdef FEAT_FOLDING | |
1211 linenr_T first; | |
1212 | |
1213 /* Make sure w_topline is at the first of a sequence of folded lines. */ | |
1214 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); | |
1215 #endif | |
1216 validate_cursor(); /* w_wrow needs to be valid */ | |
1217 while (line_count-- > 0) | |
1218 { | |
1219 #ifdef FEAT_DIFF | |
1980 | 1220 if (curwin->w_topfill < diff_check(curwin, curwin->w_topline) |
1221 && curwin->w_topfill < curwin->w_height - 1) | |
7 | 1222 { |
1223 ++curwin->w_topfill; | |
1224 ++done; | |
1225 } | |
1226 else | |
1227 #endif | |
1228 { | |
1229 if (curwin->w_topline == 1) | |
1230 break; | |
1231 --curwin->w_topline; | |
1232 #ifdef FEAT_DIFF | |
1233 curwin->w_topfill = 0; | |
1234 #endif | |
1235 #ifdef FEAT_FOLDING | |
1236 /* A sequence of folded lines only counts for one logical line */ | |
1237 if (hasFolding(curwin->w_topline, &first, NULL)) | |
1238 { | |
1239 ++done; | |
1240 if (!byfold) | |
1241 line_count -= curwin->w_topline - first - 1; | |
1242 curwin->w_botline -= curwin->w_topline - first; | |
1243 curwin->w_topline = first; | |
1244 } | |
1245 else | |
1246 #endif | |
7103
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
1247 done += PLINES_NOFILL(curwin->w_topline); |
7 | 1248 } |
1249 --curwin->w_botline; /* approximate w_botline */ | |
1250 invalidate_botline(); | |
1251 } | |
1252 curwin->w_wrow += done; /* keep w_wrow updated */ | |
1253 curwin->w_cline_row += done; /* keep w_cline_row updated */ | |
1254 | |
1255 #ifdef FEAT_DIFF | |
1256 if (curwin->w_cursor.lnum == curwin->w_topline) | |
1257 curwin->w_cline_row = 0; | |
1258 check_topfill(curwin, TRUE); | |
1259 #endif | |
1260 | |
1261 /* | |
1262 * Compute the row number of the last row of the cursor line | |
1263 * and move the cursor onto the displayed part of the window. | |
1264 */ | |
1265 wrow = curwin->w_wrow; | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12152
diff
changeset
|
1266 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 1267 { |
1268 validate_virtcol(); | |
1269 validate_cheight(); | |
1270 wrow += curwin->w_cline_height - 1 - | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
1271 curwin->w_virtcol / curwin->w_width; |
7 | 1272 } |
1273 while (wrow >= curwin->w_height && curwin->w_cursor.lnum > 1) | |
1274 { | |
1275 #ifdef FEAT_FOLDING | |
1276 if (hasFolding(curwin->w_cursor.lnum, &first, NULL)) | |
1277 { | |
1278 --wrow; | |
1279 if (first == 1) | |
1280 curwin->w_cursor.lnum = 1; | |
1281 else | |
1282 curwin->w_cursor.lnum = first - 1; | |
1283 } | |
1284 else | |
1285 #endif | |
1286 wrow -= plines(curwin->w_cursor.lnum--); | |
1287 curwin->w_valid &= | |
1288 ~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW|VALID_VIRTCOL); | |
1289 moved = TRUE; | |
1290 } | |
1291 if (moved) | |
1292 { | |
1293 #ifdef FEAT_FOLDING | |
1294 /* Move cursor to first line of closed fold. */ | |
1295 foldAdjustCursor(); | |
1296 #endif | |
1297 coladvance(curwin->w_curswant); | |
1298 } | |
1299 } | |
1300 | |
1301 /* | |
1302 * Scroll the current window up by "line_count" logical lines. "CTRL-E" | |
1303 */ | |
1304 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1305 scrollup( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1306 long line_count, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1307 int byfold UNUSED) /* TRUE: count a closed fold as one line */ |
7 | 1308 { |
1309 #if defined(FEAT_FOLDING) || defined(FEAT_DIFF) | |
1310 linenr_T lnum; | |
1311 | |
1312 if ( | |
1313 # ifdef FEAT_FOLDING | |
1314 (byfold && hasAnyFolding(curwin)) | |
1315 # ifdef FEAT_DIFF | |
1316 || | |
1317 # endif | |
1318 # endif | |
1319 # ifdef FEAT_DIFF | |
1320 curwin->w_p_diff | |
1321 # endif | |
1322 ) | |
1323 { | |
1324 /* count each sequence of folded lines as one logical line */ | |
1325 lnum = curwin->w_topline; | |
1326 while (line_count--) | |
1327 { | |
1328 # ifdef FEAT_DIFF | |
1329 if (curwin->w_topfill > 0) | |
1330 --curwin->w_topfill; | |
1331 else | |
1332 # endif | |
1333 { | |
1334 # ifdef FEAT_FOLDING | |
1335 if (byfold) | |
1336 (void)hasFolding(lnum, NULL, &lnum); | |
1337 # endif | |
1338 if (lnum >= curbuf->b_ml.ml_line_count) | |
1339 break; | |
1340 ++lnum; | |
1341 # ifdef FEAT_DIFF | |
1342 curwin->w_topfill = diff_check_fill(curwin, lnum); | |
1343 # endif | |
1344 } | |
1345 } | |
1346 /* approximate w_botline */ | |
1347 curwin->w_botline += lnum - curwin->w_topline; | |
1348 curwin->w_topline = lnum; | |
1349 } | |
1350 else | |
1351 #endif | |
1352 { | |
1353 curwin->w_topline += line_count; | |
1354 curwin->w_botline += line_count; /* approximate w_botline */ | |
1355 } | |
1356 | |
1357 if (curwin->w_topline > curbuf->b_ml.ml_line_count) | |
1358 curwin->w_topline = curbuf->b_ml.ml_line_count; | |
1359 if (curwin->w_botline > curbuf->b_ml.ml_line_count + 1) | |
1360 curwin->w_botline = curbuf->b_ml.ml_line_count + 1; | |
1361 | |
1362 #ifdef FEAT_DIFF | |
1363 check_topfill(curwin, FALSE); | |
1364 #endif | |
1365 | |
1366 #ifdef FEAT_FOLDING | |
1367 if (hasAnyFolding(curwin)) | |
1368 /* Make sure w_topline is at the first of a sequence of folded lines. */ | |
1369 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); | |
1370 #endif | |
1371 | |
1372 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); | |
1373 if (curwin->w_cursor.lnum < curwin->w_topline) | |
1374 { | |
1375 curwin->w_cursor.lnum = curwin->w_topline; | |
1376 curwin->w_valid &= | |
1377 ~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW|VALID_VIRTCOL); | |
1378 coladvance(curwin->w_curswant); | |
1379 } | |
1380 } | |
1381 | |
1382 #ifdef FEAT_DIFF | |
1383 /* | |
1384 * Don't end up with too many filler lines in the window. | |
1385 */ | |
1386 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1387 check_topfill( |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1388 win_T *wp, |
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1389 int down) /* when TRUE scroll down when not enough space */ |
7 | 1390 { |
1391 int n; | |
1392 | |
1393 if (wp->w_topfill > 0) | |
1394 { | |
1395 n = plines_win_nofill(wp, wp->w_topline, TRUE); | |
1396 if (wp->w_topfill + n > wp->w_height) | |
1397 { | |
1398 if (down && wp->w_topline > 1) | |
1399 { | |
1400 --wp->w_topline; | |
1401 wp->w_topfill = 0; | |
1402 } | |
1403 else | |
1404 { | |
1405 wp->w_topfill = wp->w_height - n; | |
1406 if (wp->w_topfill < 0) | |
1407 wp->w_topfill = 0; | |
1408 } | |
1409 } | |
1410 } | |
1411 } | |
1412 | |
1413 /* | |
1414 * Use as many filler lines as possible for w_topline. Make sure w_topline | |
1415 * is still visible. | |
1416 */ | |
1417 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1418 max_topfill(void) |
7 | 1419 { |
1420 int n; | |
1421 | |
1422 n = plines_nofill(curwin->w_topline); | |
1423 if (n >= curwin->w_height) | |
1424 curwin->w_topfill = 0; | |
1425 else | |
1426 { | |
1427 curwin->w_topfill = diff_check_fill(curwin, curwin->w_topline); | |
1428 if (curwin->w_topfill + n > curwin->w_height) | |
1429 curwin->w_topfill = curwin->w_height - n; | |
1430 } | |
1431 } | |
1432 #endif | |
1433 | |
1434 #if defined(FEAT_INS_EXPAND) || defined(PROTO) | |
1435 /* | |
1436 * Scroll the screen one line down, but don't do it if it would move the | |
1437 * cursor off the screen. | |
1438 */ | |
1439 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1440 scrolldown_clamp(void) |
7 | 1441 { |
1442 int end_row; | |
1443 #ifdef FEAT_DIFF | |
1444 int can_fill = (curwin->w_topfill | |
1445 < diff_check_fill(curwin, curwin->w_topline)); | |
1446 #endif | |
1447 | |
1448 if (curwin->w_topline <= 1 | |
1449 #ifdef FEAT_DIFF | |
1450 && !can_fill | |
1451 #endif | |
1452 ) | |
1453 return; | |
1454 | |
1455 validate_cursor(); /* w_wrow needs to be valid */ | |
1456 | |
1457 /* | |
1458 * Compute the row number of the last row of the cursor line | |
1459 * and make sure it doesn't go off the screen. Make sure the cursor | |
1460 * doesn't go past 'scrolloff' lines from the screen end. | |
1461 */ | |
1462 end_row = curwin->w_wrow; | |
1463 #ifdef FEAT_DIFF | |
1464 if (can_fill) | |
1465 ++end_row; | |
1466 else | |
1467 end_row += plines_nofill(curwin->w_topline - 1); | |
1468 #else | |
1469 end_row += plines(curwin->w_topline - 1); | |
1470 #endif | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12152
diff
changeset
|
1471 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 1472 { |
1473 validate_cheight(); | |
1474 validate_virtcol(); | |
1475 end_row += curwin->w_cline_height - 1 - | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
1476 curwin->w_virtcol / curwin->w_width; |
7 | 1477 } |
1478 if (end_row < curwin->w_height - p_so) | |
1479 { | |
1480 #ifdef FEAT_DIFF | |
1481 if (can_fill) | |
1482 { | |
1483 ++curwin->w_topfill; | |
1484 check_topfill(curwin, TRUE); | |
1485 } | |
1486 else | |
1487 { | |
1488 --curwin->w_topline; | |
1489 curwin->w_topfill = 0; | |
1490 } | |
1491 #else | |
1492 --curwin->w_topline; | |
1493 #endif | |
1494 #ifdef FEAT_FOLDING | |
7009 | 1495 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); |
7 | 1496 #endif |
1497 --curwin->w_botline; /* approximate w_botline */ | |
1498 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); | |
1499 } | |
1500 } | |
1501 | |
1502 /* | |
1503 * Scroll the screen one line up, but don't do it if it would move the cursor | |
1504 * off the screen. | |
1505 */ | |
1506 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1507 scrollup_clamp(void) |
7 | 1508 { |
1509 int start_row; | |
1510 | |
1511 if (curwin->w_topline == curbuf->b_ml.ml_line_count | |
1512 #ifdef FEAT_DIFF | |
1513 && curwin->w_topfill == 0 | |
1514 #endif | |
1515 ) | |
1516 return; | |
1517 | |
1518 validate_cursor(); /* w_wrow needs to be valid */ | |
1519 | |
1520 /* | |
1521 * Compute the row number of the first row of the cursor line | |
1522 * and make sure it doesn't go off the screen. Make sure the cursor | |
1523 * doesn't go before 'scrolloff' lines from the screen start. | |
1524 */ | |
1525 #ifdef FEAT_DIFF | |
1526 start_row = curwin->w_wrow - plines_nofill(curwin->w_topline) | |
1527 - curwin->w_topfill; | |
1528 #else | |
1529 start_row = curwin->w_wrow - plines(curwin->w_topline); | |
1530 #endif | |
12477
68d7bc045dbe
patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs
Christian Brabandt <cb@256bit.org>
parents:
12152
diff
changeset
|
1531 if (curwin->w_p_wrap && curwin->w_width != 0) |
7 | 1532 { |
1533 validate_virtcol(); | |
12515
972ea22c946f
patch 8.0.1136: W_WIDTH() is always the same
Christian Brabandt <cb@256bit.org>
parents:
12477
diff
changeset
|
1534 start_row -= curwin->w_virtcol / curwin->w_width; |
7 | 1535 } |
1536 if (start_row >= p_so) | |
1537 { | |
1538 #ifdef FEAT_DIFF | |
1539 if (curwin->w_topfill > 0) | |
1540 --curwin->w_topfill; | |
1541 else | |
1542 #endif | |
36 | 1543 { |
1544 #ifdef FEAT_FOLDING | |
1545 (void)hasFolding(curwin->w_topline, NULL, &curwin->w_topline); | |
1546 #endif | |
7 | 1547 ++curwin->w_topline; |
36 | 1548 } |
7 | 1549 ++curwin->w_botline; /* approximate w_botline */ |
1550 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); | |
1551 } | |
1552 } | |
1553 #endif /* FEAT_INS_EXPAND */ | |
1554 | |
1555 /* | |
1556 * Add one line above "lp->lnum". This can be a filler line, a closed fold or | |
1557 * a (wrapped) text line. Uses and sets "lp->fill". | |
1558 * Returns the height of the added line in "lp->height". | |
2082
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
1559 * Lines above the first one are incredibly high: MAXCOL. |
7 | 1560 */ |
1561 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1562 topline_back(lineoff_T *lp) |
7 | 1563 { |
1564 #ifdef FEAT_DIFF | |
1565 if (lp->fill < diff_check_fill(curwin, lp->lnum)) | |
1566 { | |
1567 /* Add a filler line. */ | |
1568 ++lp->fill; | |
1569 lp->height = 1; | |
1570 } | |
1571 else | |
1572 #endif | |
1573 { | |
1574 --lp->lnum; | |
1575 #ifdef FEAT_DIFF | |
1576 lp->fill = 0; | |
1577 #endif | |
1578 if (lp->lnum < 1) | |
1579 lp->height = MAXCOL; | |
1580 else | |
1581 #ifdef FEAT_FOLDING | |
1582 if (hasFolding(lp->lnum, &lp->lnum, NULL)) | |
1583 /* Add a closed fold */ | |
1584 lp->height = 1; | |
1585 else | |
1586 #endif | |
7103
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
1587 lp->height = PLINES_NOFILL(lp->lnum); |
7 | 1588 } |
1589 } | |
1590 | |
1591 /* | |
1592 * Add one line below "lp->lnum". This can be a filler line, a closed fold or | |
1593 * a (wrapped) text line. Uses and sets "lp->fill". | |
1594 * Returns the height of the added line in "lp->height". | |
1595 * Lines below the last one are incredibly high. | |
1596 */ | |
1597 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1598 botline_forw(lineoff_T *lp) |
7 | 1599 { |
1600 #ifdef FEAT_DIFF | |
1601 if (lp->fill < diff_check_fill(curwin, lp->lnum + 1)) | |
1602 { | |
1603 /* Add a filler line. */ | |
1604 ++lp->fill; | |
1605 lp->height = 1; | |
1606 } | |
1607 else | |
1608 #endif | |
1609 { | |
1610 ++lp->lnum; | |
1611 #ifdef FEAT_DIFF | |
1612 lp->fill = 0; | |
1613 #endif | |
1614 if (lp->lnum > curbuf->b_ml.ml_line_count) | |
1615 lp->height = MAXCOL; | |
1616 else | |
1617 #ifdef FEAT_FOLDING | |
1618 if (hasFolding(lp->lnum, NULL, &lp->lnum)) | |
1619 /* Add a closed fold */ | |
1620 lp->height = 1; | |
1621 else | |
1622 #endif | |
1623 { | |
7103
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
1624 lp->height = PLINES_NOFILL(lp->lnum); |
7 | 1625 } |
1626 } | |
1627 } | |
1628 | |
1629 #ifdef FEAT_DIFF | |
1630 /* | |
1631 * Switch from including filler lines below lp->lnum to including filler | |
1632 * lines above loff.lnum + 1. This keeps pointing to the same line. | |
1633 * When there are no filler lines nothing changes. | |
1634 */ | |
1635 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1636 botline_topline(lineoff_T *lp) |
7 | 1637 { |
1638 if (lp->fill > 0) | |
1639 { | |
1640 ++lp->lnum; | |
1641 lp->fill = diff_check_fill(curwin, lp->lnum) - lp->fill + 1; | |
1642 } | |
1643 } | |
1644 | |
1645 /* | |
1646 * Switch from including filler lines above lp->lnum to including filler | |
1647 * lines below loff.lnum - 1. This keeps pointing to the same line. | |
1648 * When there are no filler lines nothing changes. | |
1649 */ | |
1650 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1651 topline_botline(lineoff_T *lp) |
7 | 1652 { |
1653 if (lp->fill > 0) | |
1654 { | |
1655 lp->fill = diff_check_fill(curwin, lp->lnum) - lp->fill + 1; | |
1656 --lp->lnum; | |
1657 } | |
1658 } | |
1659 #endif | |
1660 | |
1661 /* | |
1662 * Recompute topline to put the cursor at the top of the window. | |
1663 * Scroll at least "min_scroll" lines. | |
1664 * If "always" is TRUE, always set topline (for "zt"). | |
1665 */ | |
1666 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1667 scroll_cursor_top(int min_scroll, int always) |
7 | 1668 { |
1669 int scrolled = 0; | |
1670 int extra = 0; | |
1671 int used; | |
1672 int i; | |
1673 linenr_T top; /* just above displayed lines */ | |
1674 linenr_T bot; /* just below displayed lines */ | |
1675 linenr_T old_topline = curwin->w_topline; | |
1676 #ifdef FEAT_DIFF | |
1677 linenr_T old_topfill = curwin->w_topfill; | |
1678 #endif | |
1679 linenr_T new_topline; | |
1680 int off = p_so; | |
1681 | |
1682 #ifdef FEAT_MOUSE | |
1683 if (mouse_dragging > 0) | |
1684 off = mouse_dragging - 1; | |
1685 #endif | |
1686 | |
1687 /* | |
1688 * Decrease topline until: | |
1689 * - it has become 1 | |
1690 * - (part of) the cursor line is moved off the screen or | |
1691 * - moved at least 'scrolljump' lines and | |
1692 * - at least 'scrolloff' lines above and below the cursor | |
1693 */ | |
1694 validate_cheight(); | |
7082
ad4c039349f6
commit https://github.com/vim/vim/commit/cf619daa8e0ef9a335f27f65eb74e422a17d4f92
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1695 used = curwin->w_cline_height; /* includes filler lines above */ |
7 | 1696 if (curwin->w_cursor.lnum < curwin->w_topline) |
1697 scrolled = used; | |
1698 | |
1699 #ifdef FEAT_FOLDING | |
1700 if (hasFolding(curwin->w_cursor.lnum, &top, &bot)) | |
1701 { | |
1702 --top; | |
1703 ++bot; | |
1704 } | |
1705 else | |
1706 #endif | |
1707 { | |
1708 top = curwin->w_cursor.lnum - 1; | |
1709 bot = curwin->w_cursor.lnum + 1; | |
1710 } | |
1711 new_topline = top + 1; | |
1712 | |
1713 #ifdef FEAT_DIFF | |
7088
8a58dde655a8
commit https://github.com/vim/vim/commit/a09a2c5857ab854f0870573b5160da1964c905a2
Christian Brabandt <cb@256bit.org>
parents:
7082
diff
changeset
|
1714 /* "used" already contains the number of filler lines above, don't add it |
7082
ad4c039349f6
commit https://github.com/vim/vim/commit/cf619daa8e0ef9a335f27f65eb74e422a17d4f92
Christian Brabandt <cb@256bit.org>
parents:
7009
diff
changeset
|
1715 * again. |
7088
8a58dde655a8
commit https://github.com/vim/vim/commit/a09a2c5857ab854f0870573b5160da1964c905a2
Christian Brabandt <cb@256bit.org>
parents:
7082
diff
changeset
|
1716 * Hide filler lines above cursor line by adding them to "extra". */ |
8a58dde655a8
commit https://github.com/vim/vim/commit/a09a2c5857ab854f0870573b5160da1964c905a2
Christian Brabandt <cb@256bit.org>
parents:
7082
diff
changeset
|
1717 extra += diff_check_fill(curwin, curwin->w_cursor.lnum); |
7 | 1718 #endif |
1719 | |
1720 /* | |
1721 * Check if the lines from "top" to "bot" fit in the window. If they do, | |
1722 * set new_topline and advance "top" and "bot" to include more lines. | |
1723 */ | |
1724 while (top > 0) | |
1725 { | |
1726 #ifdef FEAT_FOLDING | |
1727 if (hasFolding(top, &top, NULL)) | |
1728 /* count one logical line for a sequence of folded lines */ | |
1729 i = 1; | |
1730 else | |
1731 #endif | |
7103
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
1732 i = PLINES_NOFILL(top); |
7 | 1733 used += i; |
1734 if (extra + i <= off && bot < curbuf->b_ml.ml_line_count) | |
1735 { | |
1736 #ifdef FEAT_FOLDING | |
1737 if (hasFolding(bot, NULL, &bot)) | |
1738 /* count one logical line for a sequence of folded lines */ | |
1739 ++used; | |
1740 else | |
1741 #endif | |
1742 used += plines(bot); | |
1743 } | |
1744 if (used > curwin->w_height) | |
1745 break; | |
1746 if (top < curwin->w_topline) | |
1747 scrolled += i; | |
1748 | |
1749 /* | |
1750 * If scrolling is needed, scroll at least 'sj' lines. | |
1751 */ | |
1752 if ((new_topline >= curwin->w_topline || scrolled > min_scroll) | |
1753 && extra >= off) | |
1754 break; | |
1755 | |
1756 extra += i; | |
1757 new_topline = top; | |
1758 --top; | |
1759 ++bot; | |
1760 } | |
1761 | |
1762 /* | |
1763 * If we don't have enough space, put cursor in the middle. | |
1764 * This makes sure we get the same position when using "k" and "j" | |
1765 * in a small window. | |
1766 */ | |
1767 if (used > curwin->w_height) | |
1768 scroll_cursor_halfway(FALSE); | |
1769 else | |
1770 { | |
1771 /* | |
1772 * If "always" is FALSE, only adjust topline to a lower value, higher | |
1773 * value may happen with wrapping lines | |
1774 */ | |
1775 if (new_topline < curwin->w_topline || always) | |
1776 curwin->w_topline = new_topline; | |
1777 if (curwin->w_topline > curwin->w_cursor.lnum) | |
1778 curwin->w_topline = curwin->w_cursor.lnum; | |
1779 #ifdef FEAT_DIFF | |
1780 curwin->w_topfill = diff_check_fill(curwin, curwin->w_topline); | |
1781 if (curwin->w_topfill > 0 && extra > off) | |
1782 { | |
1783 curwin->w_topfill -= extra - off; | |
1784 if (curwin->w_topfill < 0) | |
1785 curwin->w_topfill = 0; | |
1786 } | |
1787 check_topfill(curwin, FALSE); | |
1788 #endif | |
1789 if (curwin->w_topline != old_topline | |
1790 #ifdef FEAT_DIFF | |
1791 || curwin->w_topfill != old_topfill | |
1792 #endif | |
1793 ) | |
1794 curwin->w_valid &= | |
1795 ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP); | |
1796 curwin->w_valid |= VALID_TOPLINE; | |
1797 } | |
1798 } | |
1799 | |
1800 /* | |
1801 * Set w_empty_rows and w_filler_rows for window "wp", having used up "used" | |
1802 * screen lines for text lines. | |
1803 */ | |
1804 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1805 set_empty_rows(win_T *wp, int used) |
7 | 1806 { |
1807 #ifdef FEAT_DIFF | |
1808 wp->w_filler_rows = 0; | |
1809 #endif | |
1810 if (used == 0) | |
1811 wp->w_empty_rows = 0; /* single line that doesn't fit */ | |
1812 else | |
1813 { | |
1814 wp->w_empty_rows = wp->w_height - used; | |
1815 #ifdef FEAT_DIFF | |
1816 if (wp->w_botline <= wp->w_buffer->b_ml.ml_line_count) | |
1817 { | |
1818 wp->w_filler_rows = diff_check_fill(wp, wp->w_botline); | |
1819 if (wp->w_empty_rows > wp->w_filler_rows) | |
1820 wp->w_empty_rows -= wp->w_filler_rows; | |
1821 else | |
1822 { | |
1823 wp->w_filler_rows = wp->w_empty_rows; | |
1824 wp->w_empty_rows = 0; | |
1825 } | |
1826 } | |
1827 #endif | |
1828 } | |
1829 } | |
1830 | |
1831 /* | |
1832 * Recompute topline to put the cursor at the bottom of the window. | |
1833 * Scroll at least "min_scroll" lines. | |
1834 * If "set_topbot" is TRUE, set topline and botline first (for "zb"). | |
1835 * This is messy stuff!!! | |
1836 */ | |
1837 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
1838 scroll_cursor_bot(int min_scroll, int set_topbot) |
7 | 1839 { |
1840 int used; | |
1841 int scrolled = 0; | |
1842 int extra = 0; | |
1843 int i; | |
1844 linenr_T line_count; | |
1845 linenr_T old_topline = curwin->w_topline; | |
1846 lineoff_T loff; | |
1847 lineoff_T boff; | |
1848 #ifdef FEAT_DIFF | |
1849 int old_topfill = curwin->w_topfill; | |
1850 int fill_below_window; | |
1851 #endif | |
1852 linenr_T old_botline = curwin->w_botline; | |
1853 linenr_T old_valid = curwin->w_valid; | |
1854 int old_empty_rows = curwin->w_empty_rows; | |
1855 linenr_T cln; /* Cursor Line Number */ | |
1856 | |
1857 cln = curwin->w_cursor.lnum; | |
1858 if (set_topbot) | |
1859 { | |
1860 used = 0; | |
1861 curwin->w_botline = cln + 1; | |
1862 #ifdef FEAT_DIFF | |
1863 loff.fill = 0; | |
1864 #endif | |
1865 for (curwin->w_topline = curwin->w_botline; | |
1866 curwin->w_topline > 1; | |
1867 curwin->w_topline = loff.lnum) | |
1868 { | |
1869 loff.lnum = curwin->w_topline; | |
1870 topline_back(&loff); | |
2082
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
1871 if (loff.height == MAXCOL || used + loff.height > curwin->w_height) |
7 | 1872 break; |
1873 used += loff.height; | |
1874 #ifdef FEAT_DIFF | |
1875 curwin->w_topfill = loff.fill; | |
1876 #endif | |
1877 } | |
1878 set_empty_rows(curwin, used); | |
1879 curwin->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP; | |
1880 if (curwin->w_topline != old_topline | |
1881 #ifdef FEAT_DIFF | |
1882 || curwin->w_topfill != old_topfill | |
1883 #endif | |
1884 ) | |
1885 curwin->w_valid &= ~(VALID_WROW|VALID_CROW); | |
1886 } | |
1887 else | |
1888 validate_botline(); | |
1889 | |
1890 /* The lines of the cursor line itself are always used. */ | |
1891 #ifdef FEAT_DIFF | |
1892 used = plines_nofill(cln); | |
1893 #else | |
1894 validate_cheight(); | |
1895 used = curwin->w_cline_height; | |
1896 #endif | |
1897 | |
1898 /* If the cursor is below botline, we will at least scroll by the height | |
1899 * of the cursor line. Correct for empty lines, which are really part of | |
1900 * botline. */ | |
1901 if (cln >= curwin->w_botline) | |
1902 { | |
1903 scrolled = used; | |
1904 if (cln == curwin->w_botline) | |
1905 scrolled -= curwin->w_empty_rows; | |
1906 } | |
1907 | |
1908 /* | |
1909 * Stop counting lines to scroll when | |
1910 * - hitting start of the file | |
1911 * - scrolled nothing or at least 'sj' lines | |
1912 * - at least 'so' lines below the cursor | |
1913 * - lines between botline and cursor have been counted | |
1914 */ | |
1915 #ifdef FEAT_FOLDING | |
1916 if (!hasFolding(curwin->w_cursor.lnum, &loff.lnum, &boff.lnum)) | |
1917 #endif | |
1918 { | |
1919 loff.lnum = cln; | |
1920 boff.lnum = cln; | |
1921 } | |
1922 #ifdef FEAT_DIFF | |
1923 loff.fill = 0; | |
1924 boff.fill = 0; | |
1925 fill_below_window = diff_check_fill(curwin, curwin->w_botline) | |
1926 - curwin->w_filler_rows; | |
1927 #endif | |
1928 | |
1929 while (loff.lnum > 1) | |
1930 { | |
1931 /* Stop when scrolled nothing or at least "min_scroll", found "extra" | |
1932 * context for 'scrolloff' and counted all lines below the window. */ | |
1933 if ((((scrolled <= 0 || scrolled >= min_scroll) | |
1934 && extra >= ( | |
1935 #ifdef FEAT_MOUSE | |
1121 | 1936 mouse_dragging > 0 ? mouse_dragging - 1 : |
7 | 1937 #endif |
1938 p_so)) | |
1939 || boff.lnum + 1 > curbuf->b_ml.ml_line_count) | |
1940 && loff.lnum <= curwin->w_botline | |
1941 #ifdef FEAT_DIFF | |
1942 && (loff.lnum < curwin->w_botline | |
1943 || loff.fill >= fill_below_window) | |
1944 #endif | |
1945 ) | |
1946 break; | |
1947 | |
1948 /* Add one line above */ | |
1949 topline_back(&loff); | |
2082
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
1950 if (loff.height == MAXCOL) |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
1951 used = MAXCOL; |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
1952 else |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
1953 used += loff.height; |
7 | 1954 if (used > curwin->w_height) |
1955 break; | |
1956 if (loff.lnum >= curwin->w_botline | |
1957 #ifdef FEAT_DIFF | |
1958 && (loff.lnum > curwin->w_botline | |
1959 || loff.fill <= fill_below_window) | |
1960 #endif | |
1961 ) | |
1962 { | |
1963 /* Count screen lines that are below the window. */ | |
1964 scrolled += loff.height; | |
1965 if (loff.lnum == curwin->w_botline | |
1966 #ifdef FEAT_DIFF | |
1967 && boff.fill == 0 | |
1968 #endif | |
1969 ) | |
1970 scrolled -= curwin->w_empty_rows; | |
1971 } | |
1972 | |
1973 if (boff.lnum < curbuf->b_ml.ml_line_count) | |
1974 { | |
1975 /* Add one line below */ | |
1976 botline_forw(&boff); | |
1977 used += boff.height; | |
1978 if (used > curwin->w_height) | |
1979 break; | |
1980 if (extra < ( | |
1981 #ifdef FEAT_MOUSE | |
1982 mouse_dragging > 0 ? mouse_dragging - 1 : | |
1983 #endif | |
1984 p_so) || scrolled < min_scroll) | |
1985 { | |
1986 extra += boff.height; | |
1987 if (boff.lnum >= curwin->w_botline | |
1988 #ifdef FEAT_DIFF | |
1989 || (boff.lnum + 1 == curwin->w_botline | |
1990 && boff.fill > curwin->w_filler_rows) | |
1991 #endif | |
1992 ) | |
1993 { | |
1994 /* Count screen lines that are below the window. */ | |
1995 scrolled += boff.height; | |
1996 if (boff.lnum == curwin->w_botline | |
1997 #ifdef FEAT_DIFF | |
1998 && boff.fill == 0 | |
1999 #endif | |
2000 ) | |
2001 scrolled -= curwin->w_empty_rows; | |
2002 } | |
2003 } | |
2004 } | |
2005 } | |
2006 | |
2007 /* curwin->w_empty_rows is larger, no need to scroll */ | |
2008 if (scrolled <= 0) | |
2009 line_count = 0; | |
2010 /* more than a screenfull, don't scroll but redraw */ | |
2011 else if (used > curwin->w_height) | |
2012 line_count = used; | |
2013 /* scroll minimal number of lines */ | |
2014 else | |
2015 { | |
2016 line_count = 0; | |
2017 #ifdef FEAT_DIFF | |
2018 boff.fill = curwin->w_topfill; | |
2019 #endif | |
2020 boff.lnum = curwin->w_topline - 1; | |
2021 for (i = 0; i < scrolled && boff.lnum < curwin->w_botline; ) | |
2022 { | |
2023 botline_forw(&boff); | |
2024 i += boff.height; | |
2025 ++line_count; | |
2026 } | |
2027 if (i < scrolled) /* below curwin->w_botline, don't scroll */ | |
2028 line_count = 9999; | |
2029 } | |
2030 | |
2031 /* | |
2032 * Scroll up if the cursor is off the bottom of the screen a bit. | |
2033 * Otherwise put it at 1/2 of the screen. | |
2034 */ | |
2035 if (line_count >= curwin->w_height && line_count > min_scroll) | |
2036 scroll_cursor_halfway(FALSE); | |
2037 else | |
2038 scrollup(line_count, TRUE); | |
2039 | |
2040 /* | |
2041 * If topline didn't change we need to restore w_botline and w_empty_rows | |
2042 * (we changed them). | |
2043 * If topline did change, update_screen() will set botline. | |
2044 */ | |
2045 if (curwin->w_topline == old_topline && set_topbot) | |
2046 { | |
2047 curwin->w_botline = old_botline; | |
2048 curwin->w_empty_rows = old_empty_rows; | |
2049 curwin->w_valid = old_valid; | |
2050 } | |
2051 curwin->w_valid |= VALID_TOPLINE; | |
2052 } | |
2053 | |
2054 /* | |
2055 * Recompute topline to put the cursor halfway the window | |
2056 * If "atend" is TRUE, also put it halfway at the end of the file. | |
2057 */ | |
2058 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2059 scroll_cursor_halfway(int atend) |
7 | 2060 { |
2061 int above = 0; | |
2062 linenr_T topline; | |
2063 #ifdef FEAT_DIFF | |
2064 int topfill = 0; | |
2065 #endif | |
2066 int below = 0; | |
2067 int used; | |
2068 lineoff_T loff; | |
2069 lineoff_T boff; | |
5661 | 2070 #ifdef FEAT_DIFF |
5653 | 2071 linenr_T old_topline = curwin->w_topline; |
5661 | 2072 #endif |
7 | 2073 |
2074 loff.lnum = boff.lnum = curwin->w_cursor.lnum; | |
2075 #ifdef FEAT_FOLDING | |
2076 (void)hasFolding(loff.lnum, &loff.lnum, &boff.lnum); | |
2077 #endif | |
2078 #ifdef FEAT_DIFF | |
2079 used = plines_nofill(loff.lnum); | |
2080 loff.fill = 0; | |
2081 boff.fill = 0; | |
2082 #else | |
2083 used = plines(loff.lnum); | |
2084 #endif | |
2085 topline = loff.lnum; | |
2086 while (topline > 1) | |
2087 { | |
2088 if (below <= above) /* add a line below the cursor first */ | |
2089 { | |
2090 if (boff.lnum < curbuf->b_ml.ml_line_count) | |
2091 { | |
2092 botline_forw(&boff); | |
2093 used += boff.height; | |
2094 if (used > curwin->w_height) | |
2095 break; | |
2096 below += boff.height; | |
2097 } | |
2098 else | |
2099 { | |
2100 ++below; /* count a "~" line */ | |
2101 if (atend) | |
2102 ++used; | |
2103 } | |
2104 } | |
2105 | |
2106 if (below > above) /* add a line above the cursor */ | |
2107 { | |
2108 topline_back(&loff); | |
2082
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2109 if (loff.height == MAXCOL) |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2110 used = MAXCOL; |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2111 else |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2112 used += loff.height; |
7 | 2113 if (used > curwin->w_height) |
2114 break; | |
2115 above += loff.height; | |
2116 topline = loff.lnum; | |
2117 #ifdef FEAT_DIFF | |
2118 topfill = loff.fill; | |
2119 #endif | |
2120 } | |
2121 } | |
2122 #ifdef FEAT_FOLDING | |
2123 if (!hasFolding(topline, &curwin->w_topline, NULL)) | |
2124 #endif | |
2125 curwin->w_topline = topline; | |
2126 #ifdef FEAT_DIFF | |
2127 curwin->w_topfill = topfill; | |
5653 | 2128 if (old_topline > curwin->w_topline + curwin->w_height) |
2129 curwin->w_botfill = FALSE; | |
7 | 2130 check_topfill(curwin, FALSE); |
2131 #endif | |
2132 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP); | |
2133 curwin->w_valid |= VALID_TOPLINE; | |
2134 } | |
2135 | |
2136 /* | |
2137 * Correct the cursor position so that it is in a part of the screen at least | |
2138 * 'so' lines from the top and bottom, if possible. | |
2139 * If not possible, put it at the same position as scroll_cursor_halfway(). | |
2140 * When called topline must be valid! | |
2141 */ | |
2142 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2143 cursor_correct(void) |
7 | 2144 { |
2145 int above = 0; /* screen lines above topline */ | |
2146 linenr_T topline; | |
2147 int below = 0; /* screen lines below botline */ | |
2148 linenr_T botline; | |
2149 int above_wanted, below_wanted; | |
2150 linenr_T cln; /* Cursor Line Number */ | |
2151 int max_off; | |
2152 | |
2153 /* | |
2154 * How many lines we would like to have above/below the cursor depends on | |
2155 * whether the first/last line of the file is on screen. | |
2156 */ | |
2157 above_wanted = p_so; | |
2158 below_wanted = p_so; | |
2159 #ifdef FEAT_MOUSE | |
1121 | 2160 if (mouse_dragging > 0) |
7 | 2161 { |
2162 above_wanted = mouse_dragging - 1; | |
2163 below_wanted = mouse_dragging - 1; | |
2164 } | |
2165 #endif | |
2166 if (curwin->w_topline == 1) | |
2167 { | |
2168 above_wanted = 0; | |
2169 max_off = curwin->w_height / 2; | |
2170 if (below_wanted > max_off) | |
2171 below_wanted = max_off; | |
2172 } | |
2173 validate_botline(); | |
2174 if (curwin->w_botline == curbuf->b_ml.ml_line_count + 1 | |
2175 #ifdef FEAT_MOUSE | |
1121 | 2176 && mouse_dragging == 0 |
7 | 2177 #endif |
2178 ) | |
2179 { | |
2180 below_wanted = 0; | |
2181 max_off = (curwin->w_height - 1) / 2; | |
2182 if (above_wanted > max_off) | |
2183 above_wanted = max_off; | |
2184 } | |
2185 | |
2186 /* | |
2187 * If there are sufficient file-lines above and below the cursor, we can | |
2188 * return now. | |
2189 */ | |
2190 cln = curwin->w_cursor.lnum; | |
2191 if (cln >= curwin->w_topline + above_wanted | |
2192 && cln < curwin->w_botline - below_wanted | |
2193 #ifdef FEAT_FOLDING | |
2194 && !hasAnyFolding(curwin) | |
2195 #endif | |
2196 ) | |
2197 return; | |
2198 | |
2199 /* | |
2200 * Narrow down the area where the cursor can be put by taking lines from | |
2201 * the top and the bottom until: | |
2202 * - the desired context lines are found | |
2203 * - the lines from the top is past the lines from the bottom | |
2204 */ | |
2205 topline = curwin->w_topline; | |
2206 botline = curwin->w_botline - 1; | |
2207 #ifdef FEAT_DIFF | |
2208 /* count filler lines as context */ | |
2209 above = curwin->w_topfill; | |
2210 below = curwin->w_filler_rows; | |
2211 #endif | |
2212 while ((above < above_wanted || below < below_wanted) && topline < botline) | |
2213 { | |
2214 if (below < below_wanted && (below <= above || above >= above_wanted)) | |
2215 { | |
2216 #ifdef FEAT_FOLDING | |
2217 if (hasFolding(botline, &botline, NULL)) | |
2218 ++below; | |
2219 else | |
2220 #endif | |
2221 below += plines(botline); | |
2222 --botline; | |
2223 } | |
2224 if (above < above_wanted && (above < below || below >= below_wanted)) | |
2225 { | |
2226 #ifdef FEAT_FOLDING | |
2227 if (hasFolding(topline, NULL, &topline)) | |
2228 ++above; | |
2229 else | |
2230 #endif | |
7103
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
2231 above += PLINES_NOFILL(topline); |
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
2232 #ifdef FEAT_DIFF |
7 | 2233 /* Count filler lines below this line as context. */ |
2234 if (topline < botline) | |
2235 above += diff_check_fill(curwin, topline + 1); | |
2236 #endif | |
2237 ++topline; | |
2238 } | |
2239 } | |
2240 if (topline == botline || botline == 0) | |
2241 curwin->w_cursor.lnum = topline; | |
2242 else if (topline > botline) | |
2243 curwin->w_cursor.lnum = botline; | |
2244 else | |
2245 { | |
2246 if (cln < topline && curwin->w_topline > 1) | |
2247 { | |
2248 curwin->w_cursor.lnum = topline; | |
2249 curwin->w_valid &= | |
2250 ~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW); | |
2251 } | |
2252 if (cln > botline && curwin->w_botline <= curbuf->b_ml.ml_line_count) | |
2253 { | |
2254 curwin->w_cursor.lnum = botline; | |
2255 curwin->w_valid &= | |
2256 ~(VALID_WROW|VALID_WCOL|VALID_CHEIGHT|VALID_CROW); | |
2257 } | |
2258 } | |
2259 curwin->w_valid |= VALID_TOPLINE; | |
2260 } | |
2261 | |
7803
37c929c4a073
commit https://github.com/vim/vim/commit/92b8b2d307e34117f146319872010b0ccc9d2713
Christian Brabandt <cb@256bit.org>
parents:
7103
diff
changeset
|
2262 static void get_scroll_overlap(lineoff_T *lp, int dir); |
7 | 2263 |
2264 /* | |
2265 * move screen 'count' pages up or down and update screen | |
2266 * | |
2267 * return FAIL for failure, OK otherwise | |
2268 */ | |
2269 int | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2270 onepage(int dir, long count) |
7 | 2271 { |
2272 long n; | |
2273 int retval = OK; | |
2274 lineoff_T loff; | |
2275 linenr_T old_topline = curwin->w_topline; | |
2276 | |
2277 if (curbuf->b_ml.ml_line_count == 1) /* nothing to do */ | |
2278 { | |
2279 beep_flush(); | |
2280 return FAIL; | |
2281 } | |
2282 | |
2283 for ( ; count > 0; --count) | |
2284 { | |
2285 validate_botline(); | |
2286 /* | |
2287 * It's an error to move a page up when the first line is already on | |
2288 * the screen. It's an error to move a page down when the last line | |
2289 * is on the screen and the topline is 'scrolloff' lines from the | |
2290 * last line. | |
2291 */ | |
2292 if (dir == FORWARD | |
2293 ? ((curwin->w_topline >= curbuf->b_ml.ml_line_count - p_so) | |
2294 && curwin->w_botline > curbuf->b_ml.ml_line_count) | |
2295 : (curwin->w_topline == 1 | |
2296 #ifdef FEAT_DIFF | |
2297 && curwin->w_topfill == | |
2298 diff_check_fill(curwin, curwin->w_topline) | |
2299 #endif | |
2300 )) | |
2301 { | |
2302 beep_flush(); | |
2303 retval = FAIL; | |
2304 break; | |
2305 } | |
2306 | |
2307 #ifdef FEAT_DIFF | |
2308 loff.fill = 0; | |
2309 #endif | |
2310 if (dir == FORWARD) | |
2311 { | |
10349
cf988222b150
commit https://github.com/vim/vim/commit/a1f4cb93ba50ea9e40cd4b1f5592b8a6d1398660
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
2312 if (ONE_WINDOW && p_window > 0 && p_window < Rows - 1) |
7 | 2313 { |
164 | 2314 /* Vi compatible scrolling */ |
2315 if (p_window <= 2) | |
2316 ++curwin->w_topline; | |
2317 else | |
2318 curwin->w_topline += p_window - 2; | |
2319 if (curwin->w_topline > curbuf->b_ml.ml_line_count) | |
2320 curwin->w_topline = curbuf->b_ml.ml_line_count; | |
2321 curwin->w_cursor.lnum = curwin->w_topline; | |
2322 } | |
2323 else if (curwin->w_botline > curbuf->b_ml.ml_line_count) | |
2324 { | |
2325 /* at end of file */ | |
7 | 2326 curwin->w_topline = curbuf->b_ml.ml_line_count; |
2327 #ifdef FEAT_DIFF | |
2328 curwin->w_topfill = 0; | |
2329 #endif | |
2330 curwin->w_valid &= ~(VALID_WROW|VALID_CROW); | |
2331 } | |
2332 else | |
2333 { | |
2334 /* For the overlap, start with the line just below the window | |
2335 * and go upwards. */ | |
2336 loff.lnum = curwin->w_botline; | |
2337 #ifdef FEAT_DIFF | |
2338 loff.fill = diff_check_fill(curwin, loff.lnum) | |
2339 - curwin->w_filler_rows; | |
2340 #endif | |
2341 get_scroll_overlap(&loff, -1); | |
2342 curwin->w_topline = loff.lnum; | |
2343 #ifdef FEAT_DIFF | |
2344 curwin->w_topfill = loff.fill; | |
2345 check_topfill(curwin, FALSE); | |
2346 #endif | |
2347 curwin->w_cursor.lnum = curwin->w_topline; | |
2348 curwin->w_valid &= ~(VALID_WCOL|VALID_CHEIGHT|VALID_WROW| | |
2349 VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP); | |
2350 } | |
2351 } | |
2352 else /* dir == BACKWARDS */ | |
2353 { | |
2354 #ifdef FEAT_DIFF | |
2355 if (curwin->w_topline == 1) | |
2356 { | |
2357 /* Include max number of filler lines */ | |
2358 max_topfill(); | |
2359 continue; | |
2360 } | |
2361 #endif | |
10349
cf988222b150
commit https://github.com/vim/vim/commit/a1f4cb93ba50ea9e40cd4b1f5592b8a6d1398660
Christian Brabandt <cb@256bit.org>
parents:
10295
diff
changeset
|
2362 if (ONE_WINDOW && p_window > 0 && p_window < Rows - 1) |
164 | 2363 { |
2364 /* Vi compatible scrolling (sort of) */ | |
2365 if (p_window <= 2) | |
2366 --curwin->w_topline; | |
2367 else | |
2368 curwin->w_topline -= p_window - 2; | |
2369 if (curwin->w_topline < 1) | |
2370 curwin->w_topline = 1; | |
2371 curwin->w_cursor.lnum = curwin->w_topline + p_window - 1; | |
2372 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | |
2373 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | |
2374 continue; | |
2375 } | |
2376 | |
7 | 2377 /* Find the line at the top of the window that is going to be the |
2378 * line at the bottom of the window. Make sure this results in | |
2379 * the same line as before doing CTRL-F. */ | |
2380 loff.lnum = curwin->w_topline - 1; | |
2381 #ifdef FEAT_DIFF | |
2382 loff.fill = diff_check_fill(curwin, loff.lnum + 1) | |
2383 - curwin->w_topfill; | |
2384 #endif | |
2385 get_scroll_overlap(&loff, 1); | |
2386 | |
2387 if (loff.lnum >= curbuf->b_ml.ml_line_count) | |
2388 { | |
2389 loff.lnum = curbuf->b_ml.ml_line_count; | |
2390 #ifdef FEAT_DIFF | |
2391 loff.fill = 0; | |
2392 } | |
2393 else | |
2394 { | |
2395 botline_topline(&loff); | |
2396 #endif | |
2397 } | |
2398 curwin->w_cursor.lnum = loff.lnum; | |
2399 | |
2400 /* Find the line just above the new topline to get the right line | |
2401 * at the bottom of the window. */ | |
2402 n = 0; | |
2403 while (n <= curwin->w_height && loff.lnum >= 1) | |
2404 { | |
2405 topline_back(&loff); | |
2082
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2406 if (loff.height == MAXCOL) |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2407 n = MAXCOL; |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2408 else |
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2409 n += loff.height; |
7 | 2410 } |
2082
8ca3c9ad0bee
updated for version 7.2.366
Bram Moolenaar <bram@zimbu.org>
parents:
2070
diff
changeset
|
2411 if (loff.lnum < 1) /* at begin of file */ |
7 | 2412 { |
2413 curwin->w_topline = 1; | |
2414 #ifdef FEAT_DIFF | |
2415 max_topfill(); | |
2416 #endif | |
2417 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); | |
2418 } | |
2419 else | |
2420 { | |
2421 /* Go two lines forward again. */ | |
2422 #ifdef FEAT_DIFF | |
2423 topline_botline(&loff); | |
2424 #endif | |
2425 botline_forw(&loff); | |
2426 botline_forw(&loff); | |
2427 #ifdef FEAT_DIFF | |
2428 botline_topline(&loff); | |
2429 #endif | |
2430 #ifdef FEAT_FOLDING | |
2431 /* We're at the wrong end of a fold now. */ | |
2432 (void)hasFolding(loff.lnum, &loff.lnum, NULL); | |
2433 #endif | |
2434 | |
2435 /* Always scroll at least one line. Avoid getting stuck on | |
2436 * very long lines. */ | |
2437 if (loff.lnum >= curwin->w_topline | |
2438 #ifdef FEAT_DIFF | |
2439 && (loff.lnum > curwin->w_topline | |
2440 || loff.fill >= curwin->w_topfill) | |
2441 #endif | |
2442 ) | |
2443 { | |
2444 #ifdef FEAT_DIFF | |
2445 /* First try using the maximum number of filler lines. If | |
2446 * that's not enough, backup one line. */ | |
2447 loff.fill = curwin->w_topfill; | |
2448 if (curwin->w_topfill < diff_check_fill(curwin, | |
2449 curwin->w_topline)) | |
2450 max_topfill(); | |
2451 if (curwin->w_topfill == loff.fill) | |
2452 #endif | |
2453 { | |
2454 --curwin->w_topline; | |
2455 #ifdef FEAT_DIFF | |
2456 curwin->w_topfill = 0; | |
2457 #endif | |
2458 } | |
2459 comp_botline(curwin); | |
2460 curwin->w_cursor.lnum = curwin->w_botline - 1; | |
5764 | 2461 curwin->w_valid &= |
2462 ~(VALID_WCOL|VALID_CHEIGHT|VALID_WROW|VALID_CROW); | |
7 | 2463 } |
2464 else | |
2465 { | |
2466 curwin->w_topline = loff.lnum; | |
2467 #ifdef FEAT_DIFF | |
2468 curwin->w_topfill = loff.fill; | |
2469 check_topfill(curwin, FALSE); | |
2470 #endif | |
2471 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); | |
2472 } | |
2473 } | |
2474 } | |
2475 } | |
2476 #ifdef FEAT_FOLDING | |
2477 foldAdjustCursor(); | |
2478 #endif | |
2479 cursor_correct(); | |
10102
b80ad55d62d8
commit https://github.com/vim/vim/commit/bc54f3f3fed4dc3556df8c46cee6739d211b0eb2
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
2480 check_cursor_col(); |
161 | 2481 if (retval == OK) |
2482 beginline(BL_SOL | BL_FIX); | |
7 | 2483 curwin->w_valid &= ~(VALID_WCOL|VALID_WROW|VALID_VIRTCOL); |
2484 | |
14317
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2485 if (retval == OK && dir == FORWARD) |
7 | 2486 { |
14317
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2487 // Avoid the screen jumping up and down when 'scrolloff' is non-zero. |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2488 // But make sure we scroll at least one line (happens with mix of long |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2489 // wrapping lines and non-wrapping line). |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2490 if (check_top_offset()) |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2491 { |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2492 scroll_cursor_top(1, FALSE); |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2493 if (curwin->w_topline <= old_topline |
7 | 2494 && old_topline < curbuf->b_ml.ml_line_count) |
14317
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2495 { |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2496 curwin->w_topline = old_topline + 1; |
7 | 2497 #ifdef FEAT_FOLDING |
14317
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2498 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2499 #endif |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2500 } |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2501 } |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2502 #ifdef FEAT_FOLDING |
1bc96dbb5498
patch 8.1.0174: after paging up and down fold line is wrong
Christian Brabandt <cb@256bit.org>
parents:
13384
diff
changeset
|
2503 else if (curwin->w_botline > curbuf->b_ml.ml_line_count) |
7 | 2504 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); |
2505 #endif | |
2506 } | |
2507 | |
2508 redraw_later(VALID); | |
2509 return retval; | |
2510 } | |
2511 | |
2512 /* | |
2513 * Decide how much overlap to use for page-up or page-down scrolling. | |
2514 * This is symmetric, so that doing both keeps the same lines displayed. | |
2515 * Three lines are examined: | |
2516 * | |
2517 * before CTRL-F after CTRL-F / before CTRL-B | |
2518 * etc. l1 | |
2519 * l1 last but one line ------------ | |
2520 * l2 last text line l2 top text line | |
2521 * ------------- l3 second text line | |
2522 * l3 etc. | |
2523 */ | |
2524 static void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2525 get_scroll_overlap(lineoff_T *lp, int dir) |
7 | 2526 { |
2527 int h1, h2, h3, h4; | |
2528 int min_height = curwin->w_height - 2; | |
2529 lineoff_T loff0, loff1, loff2; | |
2530 | |
2531 #ifdef FEAT_DIFF | |
2532 if (lp->fill > 0) | |
2533 lp->height = 1; | |
2534 else | |
2535 lp->height = plines_nofill(lp->lnum); | |
2536 #else | |
2537 lp->height = plines(lp->lnum); | |
2538 #endif | |
2539 h1 = lp->height; | |
2540 if (h1 > min_height) | |
2541 return; /* no overlap */ | |
2542 | |
2543 loff0 = *lp; | |
2544 if (dir > 0) | |
2545 botline_forw(lp); | |
2546 else | |
2547 topline_back(lp); | |
2548 h2 = lp->height; | |
3968 | 2549 if (h2 == MAXCOL || h2 + h1 > min_height) |
7 | 2550 { |
2551 *lp = loff0; /* no overlap */ | |
2552 return; | |
2553 } | |
2554 | |
2555 loff1 = *lp; | |
2556 if (dir > 0) | |
2557 botline_forw(lp); | |
2558 else | |
2559 topline_back(lp); | |
2560 h3 = lp->height; | |
3968 | 2561 if (h3 == MAXCOL || h3 + h2 > min_height) |
7 | 2562 { |
2563 *lp = loff0; /* no overlap */ | |
2564 return; | |
2565 } | |
2566 | |
2567 loff2 = *lp; | |
2568 if (dir > 0) | |
2569 botline_forw(lp); | |
2570 else | |
2571 topline_back(lp); | |
2572 h4 = lp->height; | |
3968 | 2573 if (h4 == MAXCOL || h4 + h3 + h2 > min_height || h3 + h2 + h1 > min_height) |
7 | 2574 *lp = loff1; /* 1 line overlap */ |
2575 else | |
2576 *lp = loff2; /* 2 lines overlap */ | |
2577 return; | |
2578 } | |
2579 | |
2580 /* #define KEEP_SCREEN_LINE */ | |
2581 /* | |
2582 * Scroll 'scroll' lines up or down. | |
2583 */ | |
2584 void | |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2585 halfpage(int flag, linenr_T Prenum) |
7 | 2586 { |
2587 long scrolled = 0; | |
2588 int i; | |
2589 int n; | |
2590 int room; | |
2591 | |
2592 if (Prenum) | |
2593 curwin->w_p_scr = (Prenum > curwin->w_height) ? | |
2594 curwin->w_height : Prenum; | |
2595 n = (curwin->w_p_scr <= curwin->w_height) ? | |
2596 curwin->w_p_scr : curwin->w_height; | |
2597 | |
11258
84f71a8a5f2c
patch 8.0.0515: ml_get errors in silent Ex mode
Christian Brabandt <cb@256bit.org>
parents:
11121
diff
changeset
|
2598 update_topline(); |
7 | 2599 validate_botline(); |
2600 room = curwin->w_empty_rows; | |
2601 #ifdef FEAT_DIFF | |
2602 room += curwin->w_filler_rows; | |
2603 #endif | |
2604 if (flag) | |
2605 { | |
2606 /* | |
2607 * scroll the text up | |
2608 */ | |
2609 while (n > 0 && curwin->w_botline <= curbuf->b_ml.ml_line_count) | |
2610 { | |
2611 #ifdef FEAT_DIFF | |
2612 if (curwin->w_topfill > 0) | |
2613 { | |
2614 i = 1; | |
2615 if (--n < 0 && scrolled > 0) | |
2616 break; | |
2617 --curwin->w_topfill; | |
2618 } | |
2619 else | |
2620 #endif | |
2621 { | |
7103
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
2622 i = PLINES_NOFILL(curwin->w_topline); |
7 | 2623 n -= i; |
2624 if (n < 0 && scrolled > 0) | |
2625 break; | |
2626 #ifdef FEAT_FOLDING | |
2627 (void)hasFolding(curwin->w_topline, NULL, &curwin->w_topline); | |
2628 #endif | |
2629 ++curwin->w_topline; | |
2630 #ifdef FEAT_DIFF | |
2631 curwin->w_topfill = diff_check_fill(curwin, curwin->w_topline); | |
2632 #endif | |
2633 | |
2634 #ifndef KEEP_SCREEN_LINE | |
2635 if (curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
2636 { | |
2637 ++curwin->w_cursor.lnum; | |
2638 curwin->w_valid &= | |
2639 ~(VALID_VIRTCOL|VALID_CHEIGHT|VALID_WCOL); | |
2640 } | |
2641 #endif | |
2642 } | |
2643 curwin->w_valid &= ~(VALID_CROW|VALID_WROW); | |
2644 scrolled += i; | |
2645 | |
2646 /* | |
2647 * Correct w_botline for changed w_topline. | |
2648 * Won't work when there are filler lines. | |
2649 */ | |
2650 #ifdef FEAT_DIFF | |
2651 if (curwin->w_p_diff) | |
2652 curwin->w_valid &= ~(VALID_BOTLINE|VALID_BOTLINE_AP); | |
2653 else | |
2654 #endif | |
2655 { | |
2656 room += i; | |
2657 do | |
2658 { | |
2659 i = plines(curwin->w_botline); | |
2660 if (i > room) | |
2661 break; | |
2662 #ifdef FEAT_FOLDING | |
2663 (void)hasFolding(curwin->w_botline, NULL, | |
2664 &curwin->w_botline); | |
2665 #endif | |
2666 ++curwin->w_botline; | |
2667 room -= i; | |
2668 } while (curwin->w_botline <= curbuf->b_ml.ml_line_count); | |
2669 } | |
2670 } | |
2671 | |
2672 #ifndef KEEP_SCREEN_LINE | |
2673 /* | |
2674 * When hit bottom of the file: move cursor down. | |
2675 */ | |
2676 if (n > 0) | |
2677 { | |
2678 # ifdef FEAT_FOLDING | |
2679 if (hasAnyFolding(curwin)) | |
2680 { | |
2681 while (--n >= 0 | |
2682 && curwin->w_cursor.lnum < curbuf->b_ml.ml_line_count) | |
2683 { | |
2684 (void)hasFolding(curwin->w_cursor.lnum, NULL, | |
2685 &curwin->w_cursor.lnum); | |
2686 ++curwin->w_cursor.lnum; | |
2687 } | |
2688 } | |
2689 else | |
2690 # endif | |
2691 curwin->w_cursor.lnum += n; | |
2692 check_cursor_lnum(); | |
2693 } | |
2694 #else | |
2695 /* try to put the cursor in the same screen line */ | |
2696 while ((curwin->w_cursor.lnum < curwin->w_topline || scrolled > 0) | |
2697 && curwin->w_cursor.lnum < curwin->w_botline - 1) | |
2698 { | |
2699 scrolled -= plines(curwin->w_cursor.lnum); | |
2700 if (scrolled < 0 && curwin->w_cursor.lnum >= curwin->w_topline) | |
2701 break; | |
2702 # ifdef FEAT_FOLDING | |
2703 (void)hasFolding(curwin->w_cursor.lnum, NULL, | |
2704 &curwin->w_cursor.lnum); | |
2705 # endif | |
2706 ++curwin->w_cursor.lnum; | |
2707 } | |
2708 #endif | |
2709 } | |
2710 else | |
2711 { | |
2712 /* | |
2713 * scroll the text down | |
2714 */ | |
2715 while (n > 0 && curwin->w_topline > 1) | |
2716 { | |
2717 #ifdef FEAT_DIFF | |
2718 if (curwin->w_topfill < diff_check_fill(curwin, curwin->w_topline)) | |
2719 { | |
2720 i = 1; | |
2721 if (--n < 0 && scrolled > 0) | |
2722 break; | |
2723 ++curwin->w_topfill; | |
2724 } | |
2725 else | |
2726 #endif | |
2727 { | |
7103
84d318257a45
commit https://github.com/vim/vim/commit/43335ea394fe247132b9701c55cccf51e6c36425
Christian Brabandt <cb@256bit.org>
parents:
7088
diff
changeset
|
2728 i = PLINES_NOFILL(curwin->w_topline - 1); |
7 | 2729 n -= i; |
2730 if (n < 0 && scrolled > 0) | |
2731 break; | |
2732 --curwin->w_topline; | |
2733 #ifdef FEAT_FOLDING | |
2734 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); | |
2735 #endif | |
2736 #ifdef FEAT_DIFF | |
2737 curwin->w_topfill = 0; | |
2738 #endif | |
2739 } | |
2740 curwin->w_valid &= ~(VALID_CROW|VALID_WROW| | |
2741 VALID_BOTLINE|VALID_BOTLINE_AP); | |
2742 scrolled += i; | |
2743 #ifndef KEEP_SCREEN_LINE | |
2744 if (curwin->w_cursor.lnum > 1) | |
2745 { | |
2746 --curwin->w_cursor.lnum; | |
2747 curwin->w_valid &= ~(VALID_VIRTCOL|VALID_CHEIGHT|VALID_WCOL); | |
2748 } | |
2749 #endif | |
2750 } | |
2751 #ifndef KEEP_SCREEN_LINE | |
2752 /* | |
2753 * When hit top of the file: move cursor up. | |
2754 */ | |
2755 if (n > 0) | |
2756 { | |
2757 if (curwin->w_cursor.lnum <= (linenr_T)n) | |
2758 curwin->w_cursor.lnum = 1; | |
2759 else | |
2760 # ifdef FEAT_FOLDING | |
2761 if (hasAnyFolding(curwin)) | |
2762 { | |
2763 while (--n >= 0 && curwin->w_cursor.lnum > 1) | |
2764 { | |
2765 --curwin->w_cursor.lnum; | |
2766 (void)hasFolding(curwin->w_cursor.lnum, | |
2767 &curwin->w_cursor.lnum, NULL); | |
2768 } | |
2769 } | |
2770 else | |
2771 # endif | |
2772 curwin->w_cursor.lnum -= n; | |
2773 } | |
2774 #else | |
2775 /* try to put the cursor in the same screen line */ | |
2776 scrolled += n; /* move cursor when topline is 1 */ | |
2777 while (curwin->w_cursor.lnum > curwin->w_topline | |
2778 && (scrolled > 0 || curwin->w_cursor.lnum >= curwin->w_botline)) | |
2779 { | |
2780 scrolled -= plines(curwin->w_cursor.lnum - 1); | |
2781 if (scrolled < 0 && curwin->w_cursor.lnum < curwin->w_botline) | |
2782 break; | |
2783 --curwin->w_cursor.lnum; | |
2784 # ifdef FEAT_FOLDING | |
2785 foldAdjustCursor(); | |
2786 # endif | |
2787 } | |
2788 #endif | |
2789 } | |
2790 # ifdef FEAT_FOLDING | |
2791 /* Move cursor to first line of closed fold. */ | |
2792 foldAdjustCursor(); | |
2793 # endif | |
2794 #ifdef FEAT_DIFF | |
2795 check_topfill(curwin, !flag); | |
2796 #endif | |
2797 cursor_correct(); | |
2798 beginline(BL_SOL | BL_FIX); | |
2799 redraw_later(VALID); | |
2800 } | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2801 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2802 void |
7829
2a8d6b2dd925
commit https://github.com/vim/vim/commit/9b57814db13c29ecb08260b36923c0e1c8a373a9
Christian Brabandt <cb@256bit.org>
parents:
7803
diff
changeset
|
2803 do_check_cursorbind(void) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2804 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2805 linenr_T line = curwin->w_cursor.lnum; |
3415 | 2806 colnr_T col = curwin->w_cursor.col; |
2807 # ifdef FEAT_VIRTUALEDIT | |
2808 colnr_T coladd = curwin->w_cursor.coladd; | |
2809 # endif | |
3433 | 2810 colnr_T curswant = curwin->w_curswant; |
2811 int set_curswant = curwin->w_set_curswant; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2812 win_T *old_curwin = curwin; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2813 buf_T *old_curbuf = curbuf; |
2693 | 2814 int restart_edit_save; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2815 int old_VIsual_select = VIsual_select; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2816 int old_VIsual_active = VIsual_active; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2817 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2818 /* |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2819 * loop through the cursorbound windows |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2820 */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2821 VIsual_select = VIsual_active = 0; |
9649
fd9727ae3c49
commit https://github.com/vim/vim/commit/2932359000b2f918d5fade79ea4d124d5943cd07
Christian Brabandt <cb@256bit.org>
parents:
8643
diff
changeset
|
2822 FOR_ALL_WINDOWS(curwin) |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2823 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2824 curbuf = curwin->w_buffer; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2825 /* skip original window and windows with 'noscrollbind' */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2826 if (curwin != old_curwin && curwin->w_p_crb) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2827 { |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2828 # ifdef FEAT_DIFF |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2829 if (curwin->w_p_diff) |
10295
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10102
diff
changeset
|
2830 curwin->w_cursor.lnum = |
d0b74b18e4b5
commit https://github.com/vim/vim/commit/025e3e0bafbc85cc4e365145af711edf99d0a90d
Christian Brabandt <cb@256bit.org>
parents:
10102
diff
changeset
|
2831 diff_get_corresponding_line(old_curbuf, line); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2832 else |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2833 # endif |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2834 curwin->w_cursor.lnum = line; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2835 curwin->w_cursor.col = col; |
3415 | 2836 # ifdef FEAT_VIRTUALEDIT |
2837 curwin->w_cursor.coladd = coladd; | |
2838 # endif | |
3433 | 2839 curwin->w_curswant = curswant; |
2840 curwin->w_set_curswant = set_curswant; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2841 |
2693 | 2842 /* Make sure the cursor is in a valid position. Temporarily set |
2843 * "restart_edit" to allow the cursor to be beyond the EOL. */ | |
2844 restart_edit_save = restart_edit; | |
2845 restart_edit = TRUE; | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2846 check_cursor(); |
10607
e39300d3d2cf
patch 8.0.0193: accidentally removed #ifdef
Christian Brabandt <cb@256bit.org>
parents:
10597
diff
changeset
|
2847 # ifdef FEAT_SYN_HL |
10597
472bff31a20a
patch 8.0.0188: redrawing for 'cursorbind' is inefficient
Christian Brabandt <cb@256bit.org>
parents:
10585
diff
changeset
|
2848 if (curwin->w_p_cul || curwin->w_p_cuc) |
10583
f91c0376f2c6
patch 8.0.0181: with cursorbind set cursor column highlighting is off
Christian Brabandt <cb@256bit.org>
parents:
10349
diff
changeset
|
2849 validate_cursor(); |
10607
e39300d3d2cf
patch 8.0.0193: accidentally removed #ifdef
Christian Brabandt <cb@256bit.org>
parents:
10597
diff
changeset
|
2850 # endif |
2693 | 2851 restart_edit = restart_edit_save; |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2852 # ifdef FEAT_MBYTE |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2853 /* Correct cursor for multi-byte character. */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2854 if (has_mbyte) |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2855 mb_adjust_cursor(); |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2856 # endif |
10597
472bff31a20a
patch 8.0.0188: redrawing for 'cursorbind' is inefficient
Christian Brabandt <cb@256bit.org>
parents:
10585
diff
changeset
|
2857 redraw_later(VALID); |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2858 |
2688 | 2859 /* Only scroll when 'scrollbind' hasn't done this. */ |
2860 if (!curwin->w_p_scb) | |
2861 update_topline(); | |
2250
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2862 curwin->w_redr_status = TRUE; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2863 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2864 } |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2865 |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2866 /* |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2867 * reset current-window |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2868 */ |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2869 VIsual_select = old_VIsual_select; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2870 VIsual_active = old_VIsual_active; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2871 curwin = old_curwin; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2872 curbuf = old_curbuf; |
1bac28a53fae
Add the conceal patch from Vince Negri.
Bram Moolenaar <bram@vim.org>
parents:
2210
diff
changeset
|
2873 } |