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