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