Mercurial > vim
comparison src/move.c @ 18931:80b40bd5ec1a v8.2.0026
patch 8.2.0026: still some /* */ comments
Commit: https://github.com/vim/vim/commit/85a2002adb0eda9a9309c2fab4a79edaa91fb834
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Dec 21 18:25:54 2019 +0100
patch 8.2.0026: still some /* */ comments
Problem: Still some /* */ comments.
Solution: Convert to // comments.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 21 Dec 2019 18:30:05 +0100 |
parents | fb2d26bc8ca1 |
children | 9e428147e4ee |
comparison
equal
deleted
inserted
replaced
18930:394f34c5c683 | 18931:80b40bd5ec1a |
---|---|
23 static int check_top_offset(void); | 23 static int check_top_offset(void); |
24 static void curs_rows(win_T *wp); | 24 static void curs_rows(win_T *wp); |
25 | 25 |
26 typedef struct | 26 typedef struct |
27 { | 27 { |
28 linenr_T lnum; /* line number */ | 28 linenr_T lnum; // line number |
29 #ifdef FEAT_DIFF | 29 #ifdef FEAT_DIFF |
30 int fill; /* filler lines */ | 30 int fill; // filler lines |
31 #endif | 31 #endif |
32 int height; /* height of added line */ | 32 int height; // height of added line |
33 } lineoff_T; | 33 } lineoff_T; |
34 | 34 |
35 static void topline_back(lineoff_T *lp); | 35 static void topline_back(lineoff_T *lp); |
36 static void botline_forw(lineoff_T *lp); | 36 static void botline_forw(lineoff_T *lp); |
37 | 37 |
106 #ifdef FEAT_FOLDING | 106 #ifdef FEAT_FOLDING |
107 lnum = last; | 107 lnum = last; |
108 #endif | 108 #endif |
109 } | 109 } |
110 | 110 |
111 /* wp->w_botline is the line that is just below the window */ | 111 // wp->w_botline is the line that is just below the window |
112 wp->w_botline = lnum; | 112 wp->w_botline = lnum; |
113 wp->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP; | 113 wp->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP; |
114 | 114 |
115 set_empty_rows(wp, done); | 115 set_empty_rows(wp, done); |
116 } | 116 } |
190 int check_topline = FALSE; | 190 int check_topline = FALSE; |
191 int check_botline = FALSE; | 191 int check_botline = FALSE; |
192 long *so_ptr = curwin->w_p_so >= 0 ? &curwin->w_p_so : &p_so; | 192 long *so_ptr = curwin->w_p_so >= 0 ? &curwin->w_p_so : &p_so; |
193 int save_so = *so_ptr; | 193 int save_so = *so_ptr; |
194 | 194 |
195 /* If there is no valid screen and when the window height is zero just use | 195 // If there is no valid screen and when the window height is zero just use |
196 * the cursor line. */ | 196 // the cursor line. |
197 if (!screen_valid(TRUE) || curwin->w_height == 0) | 197 if (!screen_valid(TRUE) || curwin->w_height == 0) |
198 { | 198 { |
199 curwin->w_topline = curwin->w_cursor.lnum; | 199 curwin->w_topline = curwin->w_cursor.lnum; |
200 curwin->w_botline = curwin->w_topline; | 200 curwin->w_botline = curwin->w_topline; |
201 curwin->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP; | 201 curwin->w_valid |= VALID_BOTLINE|VALID_BOTLINE_AP; |
205 | 205 |
206 check_cursor_moved(curwin); | 206 check_cursor_moved(curwin); |
207 if (curwin->w_valid & VALID_TOPLINE) | 207 if (curwin->w_valid & VALID_TOPLINE) |
208 return; | 208 return; |
209 | 209 |
210 /* When dragging with the mouse, don't scroll that quickly */ | 210 // When dragging with the mouse, don't scroll that quickly |
211 if (mouse_dragging > 0) | 211 if (mouse_dragging > 0) |
212 *so_ptr = mouse_dragging - 1; | 212 *so_ptr = mouse_dragging - 1; |
213 | 213 |
214 old_topline = curwin->w_topline; | 214 old_topline = curwin->w_topline; |
215 #ifdef FEAT_DIFF | 215 #ifdef FEAT_DIFF |
217 #endif | 217 #endif |
218 | 218 |
219 /* | 219 /* |
220 * If the buffer is empty, always set topline to 1. | 220 * If the buffer is empty, always set topline to 1. |
221 */ | 221 */ |
222 if (BUFEMPTY()) /* special case - file is empty */ | 222 if (BUFEMPTY()) // special case - file is empty |
223 { | 223 { |
224 if (curwin->w_topline != 1) | 224 if (curwin->w_topline != 1) |
225 redraw_later(NOT_VALID); | 225 redraw_later(NOT_VALID); |
226 curwin->w_topline = 1; | 226 curwin->w_topline = 1; |
227 curwin->w_botline = 2; | 227 curwin->w_botline = 2; |
235 */ | 235 */ |
236 else | 236 else |
237 { | 237 { |
238 if (curwin->w_topline > 1) | 238 if (curwin->w_topline > 1) |
239 { | 239 { |
240 /* If the cursor is above topline, scrolling is always needed. | 240 // If the cursor is above topline, scrolling is always needed. |
241 * If the cursor is far below topline and there is no folding, | 241 // If the cursor is far below topline and there is no folding, |
242 * scrolling down is never needed. */ | 242 // scrolling down is never needed. |
243 if (curwin->w_cursor.lnum < curwin->w_topline) | 243 if (curwin->w_cursor.lnum < curwin->w_topline) |
244 check_topline = TRUE; | 244 check_topline = TRUE; |
245 else if (check_top_offset()) | 245 else if (check_top_offset()) |
246 check_topline = TRUE; | 246 check_topline = TRUE; |
247 } | 247 } |
248 #ifdef FEAT_DIFF | 248 #ifdef FEAT_DIFF |
249 /* Check if there are more filler lines than allowed. */ | 249 // Check if there are more filler lines than allowed. |
250 if (!check_topline && curwin->w_topfill > diff_check_fill(curwin, | 250 if (!check_topline && curwin->w_topfill > diff_check_fill(curwin, |
251 curwin->w_topline)) | 251 curwin->w_topline)) |
252 check_topline = TRUE; | 252 check_topline = TRUE; |
253 #endif | 253 #endif |
254 | 254 |
259 halfheight = 2; | 259 halfheight = 2; |
260 | 260 |
261 #ifdef FEAT_FOLDING | 261 #ifdef FEAT_FOLDING |
262 if (hasAnyFolding(curwin)) | 262 if (hasAnyFolding(curwin)) |
263 { | 263 { |
264 /* Count the number of logical lines between the cursor and | 264 // Count the number of logical lines between the cursor and |
265 * topline + scrolloff (approximation of how much will be | 265 // topline + scrolloff (approximation of how much will be |
266 * scrolled). */ | 266 // scrolled). |
267 n = 0; | 267 n = 0; |
268 for (lnum = curwin->w_cursor.lnum; | 268 for (lnum = curwin->w_cursor.lnum; |
269 lnum < curwin->w_topline + *so_ptr; ++lnum) | 269 lnum < curwin->w_topline + *so_ptr; ++lnum) |
270 { | 270 { |
271 ++n; | 271 ++n; |
272 /* stop at end of file or when we know we are far off */ | 272 // stop at end of file or when we know we are far off |
273 if (lnum >= curbuf->b_ml.ml_line_count || n >= halfheight) | 273 if (lnum >= curbuf->b_ml.ml_line_count || n >= halfheight) |
274 break; | 274 break; |
275 (void)hasFolding(lnum, NULL, &lnum); | 275 (void)hasFolding(lnum, NULL, &lnum); |
276 } | 276 } |
277 } | 277 } |
278 else | 278 else |
279 #endif | 279 #endif |
280 n = curwin->w_topline + *so_ptr - curwin->w_cursor.lnum; | 280 n = curwin->w_topline + *so_ptr - curwin->w_cursor.lnum; |
281 | 281 |
282 /* If we weren't very close to begin with, we scroll to put the | 282 // If we weren't very close to begin with, we scroll to put the |
283 * cursor in the middle of the window. Otherwise put the cursor | 283 // cursor in the middle of the window. Otherwise put the cursor |
284 * near the top of the window. */ | 284 // near the top of the window. |
285 if (n >= halfheight) | 285 if (n >= halfheight) |
286 scroll_cursor_halfway(FALSE); | 286 scroll_cursor_halfway(FALSE); |
287 else | 287 else |
288 { | 288 { |
289 scroll_cursor_top(scrolljump_value(), FALSE); | 289 scroll_cursor_top(scrolljump_value(), FALSE); |
292 } | 292 } |
293 | 293 |
294 else | 294 else |
295 { | 295 { |
296 #ifdef FEAT_FOLDING | 296 #ifdef FEAT_FOLDING |
297 /* Make sure topline is the first line of a fold. */ | 297 // Make sure topline is the first line of a fold. |
298 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); | 298 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); |
299 #endif | 299 #endif |
300 check_botline = TRUE; | 300 check_botline = TRUE; |
301 } | 301 } |
302 } | 302 } |
325 #endif | 325 #endif |
326 )) | 326 )) |
327 { | 327 { |
328 lineoff_T loff; | 328 lineoff_T loff; |
329 | 329 |
330 /* Cursor is (a few lines) above botline, check if there are | 330 // Cursor is (a few lines) above botline, check if there are |
331 * 'scrolloff' window lines below the cursor. If not, need to | 331 // 'scrolloff' window lines below the cursor. If not, need to |
332 * scroll. */ | 332 // scroll. |
333 n = curwin->w_empty_rows; | 333 n = curwin->w_empty_rows; |
334 loff.lnum = curwin->w_cursor.lnum; | 334 loff.lnum = curwin->w_cursor.lnum; |
335 #ifdef FEAT_FOLDING | 335 #ifdef FEAT_FOLDING |
336 /* In a fold go to its last line. */ | 336 // In a fold go to its last line. |
337 (void)hasFolding(loff.lnum, NULL, &loff.lnum); | 337 (void)hasFolding(loff.lnum, NULL, &loff.lnum); |
338 #endif | 338 #endif |
339 #ifdef FEAT_DIFF | 339 #ifdef FEAT_DIFF |
340 loff.fill = 0; | 340 loff.fill = 0; |
341 n += curwin->w_filler_rows; | 341 n += curwin->w_filler_rows; |
351 if (n >= *so_ptr) | 351 if (n >= *so_ptr) |
352 break; | 352 break; |
353 botline_forw(&loff); | 353 botline_forw(&loff); |
354 } | 354 } |
355 if (n >= *so_ptr) | 355 if (n >= *so_ptr) |
356 /* sufficient context, no need to scroll */ | 356 // sufficient context, no need to scroll |
357 check_botline = FALSE; | 357 check_botline = FALSE; |
358 } | 358 } |
359 else | 359 else |
360 /* sufficient context, no need to scroll */ | 360 // sufficient context, no need to scroll |
361 check_botline = FALSE; | 361 check_botline = FALSE; |
362 } | 362 } |
363 if (check_botline) | 363 if (check_botline) |
364 { | 364 { |
365 #ifdef FEAT_FOLDING | 365 #ifdef FEAT_FOLDING |
366 if (hasAnyFolding(curwin)) | 366 if (hasAnyFolding(curwin)) |
367 { | 367 { |
368 /* Count the number of logical lines between the cursor and | 368 // Count the number of logical lines between the cursor and |
369 * botline - scrolloff (approximation of how much will be | 369 // botline - scrolloff (approximation of how much will be |
370 * scrolled). */ | 370 // scrolled). |
371 line_count = 0; | 371 line_count = 0; |
372 for (lnum = curwin->w_cursor.lnum; | 372 for (lnum = curwin->w_cursor.lnum; |
373 lnum >= curwin->w_botline - *so_ptr; --lnum) | 373 lnum >= curwin->w_botline - *so_ptr; --lnum) |
374 { | 374 { |
375 ++line_count; | 375 ++line_count; |
376 /* stop at end of file or when we know we are far off */ | 376 // stop at end of file or when we know we are far off |
377 if (lnum <= 0 || line_count > curwin->w_height + 1) | 377 if (lnum <= 0 || line_count > curwin->w_height + 1) |
378 break; | 378 break; |
379 (void)hasFolding(lnum, &lnum, NULL); | 379 (void)hasFolding(lnum, &lnum, NULL); |
380 } | 380 } |
381 } | 381 } |
407 curwin->w_skipcol = 0; | 407 curwin->w_skipcol = 0; |
408 redraw_later(NOT_VALID); | 408 redraw_later(NOT_VALID); |
409 } | 409 } |
410 else | 410 else |
411 redraw_later(VALID); | 411 redraw_later(VALID); |
412 /* May need to set w_skipcol when cursor in w_topline. */ | 412 // May need to set w_skipcol when cursor in w_topline. |
413 if (curwin->w_cursor.lnum == curwin->w_topline) | 413 if (curwin->w_cursor.lnum == curwin->w_topline) |
414 validate_cursor(); | 414 validate_cursor(); |
415 } | 415 } |
416 | 416 |
417 *so_ptr = save_so; | 417 *so_ptr = save_so; |
448 ) | 448 ) |
449 { | 449 { |
450 loff.lnum = curwin->w_cursor.lnum; | 450 loff.lnum = curwin->w_cursor.lnum; |
451 #ifdef FEAT_DIFF | 451 #ifdef FEAT_DIFF |
452 loff.fill = 0; | 452 loff.fill = 0; |
453 n = curwin->w_topfill; /* always have this context */ | 453 n = curwin->w_topfill; // always have this context |
454 #else | 454 #else |
455 n = 0; | 455 n = 0; |
456 #endif | 456 #endif |
457 /* Count the visible screen lines above the cursor line. */ | 457 // Count the visible screen lines above the cursor line. |
458 while (n < so) | 458 while (n < so) |
459 { | 459 { |
460 topline_back(&loff); | 460 topline_back(&loff); |
461 /* Stop when included a line above the window. */ | 461 // Stop when included a line above the window. |
462 if (loff.lnum < curwin->w_topline | 462 if (loff.lnum < curwin->w_topline |
463 #ifdef FEAT_DIFF | 463 #ifdef FEAT_DIFF |
464 || (loff.lnum == curwin->w_topline && loff.fill > 0) | 464 || (loff.lnum == curwin->w_topline && loff.fill > 0) |
465 #endif | 465 #endif |
466 ) | 466 ) |
533 */ | 533 */ |
534 void | 534 void |
535 set_topline(win_T *wp, linenr_T lnum) | 535 set_topline(win_T *wp, linenr_T lnum) |
536 { | 536 { |
537 #ifdef FEAT_FOLDING | 537 #ifdef FEAT_FOLDING |
538 /* go to first of folded lines */ | 538 // go to first of folded lines |
539 (void)hasFoldingWin(wp, lnum, &lnum, NULL, TRUE, NULL); | 539 (void)hasFoldingWin(wp, lnum, &lnum, NULL, TRUE, NULL); |
540 #endif | 540 #endif |
541 /* Approximate the value of w_botline */ | 541 // Approximate the value of w_botline |
542 wp->w_botline += lnum - wp->w_topline; | 542 wp->w_botline += lnum - wp->w_topline; |
543 wp->w_topline = lnum; | 543 wp->w_topline = lnum; |
544 wp->w_topline_was_set = TRUE; | 544 wp->w_topline_was_set = TRUE; |
545 #ifdef FEAT_DIFF | 545 #ifdef FEAT_DIFF |
546 wp->w_topfill = 0; | 546 wp->w_topfill = 0; |
547 #endif | 547 #endif |
548 wp->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_TOPLINE); | 548 wp->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE|VALID_TOPLINE); |
549 /* Don't set VALID_TOPLINE here, 'scrolloff' needs to be checked. */ | 549 // Don't set VALID_TOPLINE here, 'scrolloff' needs to be checked. |
550 redraw_later(VALID); | 550 redraw_later(VALID); |
551 } | 551 } |
552 | 552 |
553 /* | 553 /* |
554 * Call this function when the length of the cursor line (in screen | 554 * Call this function when the length of the cursor line (in screen |
673 int valid; | 673 int valid; |
674 #ifdef FEAT_FOLDING | 674 #ifdef FEAT_FOLDING |
675 long fold_count; | 675 long fold_count; |
676 #endif | 676 #endif |
677 | 677 |
678 /* Check if wp->w_lines[].wl_size is invalid */ | 678 // Check if wp->w_lines[].wl_size is invalid |
679 all_invalid = (!redrawing() | 679 all_invalid = (!redrawing() |
680 || wp->w_lines_valid == 0 | 680 || wp->w_lines_valid == 0 |
681 || wp->w_lines[0].wl_lnum > wp->w_topline); | 681 || wp->w_lines[0].wl_lnum > wp->w_topline); |
682 i = 0; | 682 i = 0; |
683 wp->w_cline_row = 0; | 683 wp->w_cline_row = 0; |
685 { | 685 { |
686 valid = FALSE; | 686 valid = FALSE; |
687 if (!all_invalid && i < wp->w_lines_valid) | 687 if (!all_invalid && i < wp->w_lines_valid) |
688 { | 688 { |
689 if (wp->w_lines[i].wl_lnum < lnum || !wp->w_lines[i].wl_valid) | 689 if (wp->w_lines[i].wl_lnum < lnum || !wp->w_lines[i].wl_valid) |
690 continue; /* skip changed or deleted lines */ | 690 continue; // skip changed or deleted lines |
691 if (wp->w_lines[i].wl_lnum == lnum) | 691 if (wp->w_lines[i].wl_lnum == lnum) |
692 { | 692 { |
693 #ifdef FEAT_FOLDING | 693 #ifdef FEAT_FOLDING |
694 /* Check for newly inserted lines below this row, in which | 694 // Check for newly inserted lines below this row, in which |
695 * case we need to check for folded lines. */ | 695 // case we need to check for folded lines. |
696 if (!wp->w_buffer->b_mod_set | 696 if (!wp->w_buffer->b_mod_set |
697 || wp->w_lines[i].wl_lastlnum < wp->w_cursor.lnum | 697 || wp->w_lines[i].wl_lastlnum < wp->w_cursor.lnum |
698 || wp->w_buffer->b_mod_top | 698 || wp->w_buffer->b_mod_top |
699 > wp->w_lines[i].wl_lastlnum + 1) | 699 > wp->w_lines[i].wl_lastlnum + 1) |
700 #endif | 700 #endif |
701 valid = TRUE; | 701 valid = TRUE; |
702 } | 702 } |
703 else if (wp->w_lines[i].wl_lnum > lnum) | 703 else if (wp->w_lines[i].wl_lnum > lnum) |
704 --i; /* hold at inserted lines */ | 704 --i; // hold at inserted lines |
705 } | 705 } |
706 if (valid | 706 if (valid |
707 #ifdef FEAT_DIFF | 707 #ifdef FEAT_DIFF |
708 && (lnum != wp->w_topline || !wp->w_p_diff) | 708 && (lnum != wp->w_topline || !wp->w_p_diff) |
709 #endif | 709 #endif |
710 ) | 710 ) |
711 { | 711 { |
712 #ifdef FEAT_FOLDING | 712 #ifdef FEAT_FOLDING |
713 lnum = wp->w_lines[i].wl_lastlnum + 1; | 713 lnum = wp->w_lines[i].wl_lastlnum + 1; |
714 /* Cursor inside folded lines, don't count this row */ | 714 // Cursor inside folded lines, don't count this row |
715 if (lnum > wp->w_cursor.lnum) | 715 if (lnum > wp->w_cursor.lnum) |
716 break; | 716 break; |
717 #else | 717 #else |
718 ++lnum; | 718 ++lnum; |
719 #endif | 719 #endif |
763 NULL, NULL, TRUE, NULL); | 763 NULL, NULL, TRUE, NULL); |
764 #endif | 764 #endif |
765 } | 765 } |
766 else if (i > wp->w_lines_valid) | 766 else if (i > wp->w_lines_valid) |
767 { | 767 { |
768 /* a line that is too long to fit on the last screen line */ | 768 // a line that is too long to fit on the last screen line |
769 wp->w_cline_height = 0; | 769 wp->w_cline_height = 0; |
770 #ifdef FEAT_FOLDING | 770 #ifdef FEAT_FOLDING |
771 wp->w_cline_folded = hasFoldingWin(wp, wp->w_cursor.lnum, | 771 wp->w_cline_folded = hasFoldingWin(wp, wp->w_cursor.lnum, |
772 NULL, NULL, TRUE, NULL); | 772 NULL, NULL, TRUE, NULL); |
773 #endif | 773 #endif |
852 col = curwin->w_virtcol; | 852 col = curwin->w_virtcol; |
853 off = curwin_col_off(); | 853 off = curwin_col_off(); |
854 col += off; | 854 col += off; |
855 width = curwin->w_width - off + curwin_col_off2(); | 855 width = curwin->w_width - off + curwin_col_off2(); |
856 | 856 |
857 /* long line wrapping, adjust curwin->w_wrow */ | 857 // long line wrapping, adjust curwin->w_wrow |
858 if (curwin->w_p_wrap | 858 if (curwin->w_p_wrap |
859 && col >= (colnr_T)curwin->w_width | 859 && col >= (colnr_T)curwin->w_width |
860 && width > 0) | 860 && width > 0) |
861 /* use same formula as what is used in curs_columns() */ | 861 // use same formula as what is used in curs_columns() |
862 col -= ((col - curwin->w_width) / width + 1) * width; | 862 col -= ((col - curwin->w_width) / width + 1) * width; |
863 if (col > (int)curwin->w_leftcol) | 863 if (col > (int)curwin->w_leftcol) |
864 col -= curwin->w_leftcol; | 864 col -= curwin->w_leftcol; |
865 else | 865 else |
866 col = 0; | 866 col = 0; |
920 * Also updates curwin->w_wrow and curwin->w_cline_row. | 920 * Also updates curwin->w_wrow and curwin->w_cline_row. |
921 * Also updates curwin->w_leftcol. | 921 * Also updates curwin->w_leftcol. |
922 */ | 922 */ |
923 void | 923 void |
924 curs_columns( | 924 curs_columns( |
925 int may_scroll) /* when TRUE, may scroll horizontally */ | 925 int may_scroll) // when TRUE, may scroll horizontally |
926 { | 926 { |
927 int diff; | 927 int diff; |
928 int extra; /* offset for first screen line */ | 928 int extra; // offset for first screen line |
929 int off_left, off_right; | 929 int off_left, off_right; |
930 int n; | 930 int n; |
931 int p_lines; | 931 int p_lines; |
932 int width = 0; | 932 int width = 0; |
933 int textwidth; | 933 int textwidth; |
952 /* | 952 /* |
953 * Compute the number of virtual columns. | 953 * Compute the number of virtual columns. |
954 */ | 954 */ |
955 #ifdef FEAT_FOLDING | 955 #ifdef FEAT_FOLDING |
956 if (curwin->w_cline_folded) | 956 if (curwin->w_cline_folded) |
957 /* In a folded line the cursor is always in the first column */ | 957 // In a folded line the cursor is always in the first column |
958 startcol = curwin->w_virtcol = endcol = curwin->w_leftcol; | 958 startcol = curwin->w_virtcol = endcol = curwin->w_leftcol; |
959 else | 959 else |
960 #endif | 960 #endif |
961 getvvcol(curwin, &curwin->w_cursor, | 961 getvvcol(curwin, &curwin->w_cursor, |
962 &startcol, &(curwin->w_virtcol), &endcol); | 962 &startcol, &(curwin->w_virtcol), &endcol); |
963 | 963 |
964 /* remove '$' from change command when cursor moves onto it */ | 964 // remove '$' from change command when cursor moves onto it |
965 if (startcol > dollar_vcol) | 965 if (startcol > dollar_vcol) |
966 dollar_vcol = -1; | 966 dollar_vcol = -1; |
967 | 967 |
968 extra = curwin_col_off(); | 968 extra = curwin_col_off(); |
969 curwin->w_wcol = curwin->w_virtcol + extra; | 969 curwin->w_wcol = curwin->w_virtcol + extra; |
975 curwin->w_wrow = curwin->w_cline_row; | 975 curwin->w_wrow = curwin->w_cline_row; |
976 | 976 |
977 textwidth = curwin->w_width - extra; | 977 textwidth = curwin->w_width - extra; |
978 if (textwidth <= 0) | 978 if (textwidth <= 0) |
979 { | 979 { |
980 /* No room for text, put cursor in last char of window. */ | 980 // No room for text, put cursor in last char of window. |
981 curwin->w_wcol = curwin->w_width - 1; | 981 curwin->w_wcol = curwin->w_width - 1; |
982 curwin->w_wrow = curwin->w_height - 1; | 982 curwin->w_wrow = curwin->w_height - 1; |
983 } | 983 } |
984 else if (curwin->w_p_wrap && curwin->w_width != 0) | 984 else if (curwin->w_p_wrap && curwin->w_width != 0) |
985 { | 985 { |
986 width = textwidth + curwin_col_off2(); | 986 width = textwidth + curwin_col_off2(); |
987 | 987 |
988 /* long line wrapping, adjust curwin->w_wrow */ | 988 // long line wrapping, adjust curwin->w_wrow |
989 if (curwin->w_wcol >= curwin->w_width) | 989 if (curwin->w_wcol >= curwin->w_width) |
990 { | 990 { |
991 #ifdef FEAT_LINEBREAK | 991 #ifdef FEAT_LINEBREAK |
992 char_u *sbr; | 992 char_u *sbr; |
993 #endif | 993 #endif |
994 | 994 |
995 /* this same formula is used in validate_cursor_col() */ | 995 // this same formula is used in validate_cursor_col() |
996 n = (curwin->w_wcol - curwin->w_width) / width + 1; | 996 n = (curwin->w_wcol - curwin->w_width) / width + 1; |
997 curwin->w_wcol -= n * width; | 997 curwin->w_wcol -= n * width; |
998 curwin->w_wrow += n; | 998 curwin->w_wrow += n; |
999 | 999 |
1000 #ifdef FEAT_LINEBREAK | 1000 #ifdef FEAT_LINEBREAK |
1001 /* When cursor wraps to first char of next line in Insert | 1001 // When cursor wraps to first char of next line in Insert |
1002 * mode, the 'showbreak' string isn't shown, backup to first | 1002 // mode, the 'showbreak' string isn't shown, backup to first |
1003 * column */ | 1003 // column |
1004 sbr = get_showbreak_value(curwin); | 1004 sbr = get_showbreak_value(curwin); |
1005 if (*sbr && *ml_get_cursor() == NUL | 1005 if (*sbr && *ml_get_cursor() == NUL |
1006 && curwin->w_wcol == (int)vim_strsize(sbr)) | 1006 && curwin->w_wcol == (int)vim_strsize(sbr)) |
1007 curwin->w_wcol = 0; | 1007 curwin->w_wcol = 0; |
1008 #endif | 1008 #endif |
1009 } | 1009 } |
1010 } | 1010 } |
1011 | 1011 |
1012 /* No line wrapping: compute curwin->w_leftcol if scrolling is on and line | 1012 // No line wrapping: compute curwin->w_leftcol if scrolling is on and line |
1013 * is not folded. | 1013 // is not folded. |
1014 * If scrolling is off, curwin->w_leftcol is assumed to be 0 */ | 1014 // If scrolling is off, curwin->w_leftcol is assumed to be 0 |
1015 else if (may_scroll | 1015 else if (may_scroll |
1016 #ifdef FEAT_FOLDING | 1016 #ifdef FEAT_FOLDING |
1017 && !curwin->w_cline_folded | 1017 && !curwin->w_cline_folded |
1018 #endif | 1018 #endif |
1019 ) | 1019 ) |
1032 if (off_left < 0) | 1032 if (off_left < 0) |
1033 diff = -off_left; | 1033 diff = -off_left; |
1034 else | 1034 else |
1035 diff = off_right; | 1035 diff = off_right; |
1036 | 1036 |
1037 /* When far off or not enough room on either side, put cursor in | 1037 // When far off or not enough room on either side, put cursor in |
1038 * middle of window. */ | 1038 // middle of window. |
1039 if (p_ss == 0 || diff >= textwidth / 2 || off_right >= off_left) | 1039 if (p_ss == 0 || diff >= textwidth / 2 || off_right >= off_left) |
1040 new_leftcol = curwin->w_wcol - extra - textwidth / 2; | 1040 new_leftcol = curwin->w_wcol - extra - textwidth / 2; |
1041 else | 1041 else |
1042 { | 1042 { |
1043 if (diff < p_ss) | 1043 if (diff < p_ss) |
1050 if (new_leftcol < 0) | 1050 if (new_leftcol < 0) |
1051 new_leftcol = 0; | 1051 new_leftcol = 0; |
1052 if (new_leftcol != (int)curwin->w_leftcol) | 1052 if (new_leftcol != (int)curwin->w_leftcol) |
1053 { | 1053 { |
1054 curwin->w_leftcol = new_leftcol; | 1054 curwin->w_leftcol = new_leftcol; |
1055 /* screen has to be redrawn with new curwin->w_leftcol */ | 1055 // screen has to be redrawn with new curwin->w_leftcol |
1056 redraw_later(NOT_VALID); | 1056 redraw_later(NOT_VALID); |
1057 } | 1057 } |
1058 } | 1058 } |
1059 curwin->w_wcol -= curwin->w_leftcol; | 1059 curwin->w_wcol -= curwin->w_leftcol; |
1060 } | 1060 } |
1062 curwin->w_wcol -= curwin->w_leftcol; | 1062 curwin->w_wcol -= curwin->w_leftcol; |
1063 else | 1063 else |
1064 curwin->w_wcol = 0; | 1064 curwin->w_wcol = 0; |
1065 | 1065 |
1066 #ifdef FEAT_DIFF | 1066 #ifdef FEAT_DIFF |
1067 /* Skip over filler lines. At the top use w_topfill, there | 1067 // Skip over filler lines. At the top use w_topfill, there |
1068 * may be some filler lines above the window. */ | 1068 // may be some filler lines above the window. |
1069 if (curwin->w_cursor.lnum == curwin->w_topline) | 1069 if (curwin->w_cursor.lnum == curwin->w_topline) |
1070 curwin->w_wrow += curwin->w_topfill; | 1070 curwin->w_wrow += curwin->w_topfill; |
1071 else | 1071 else |
1072 curwin->w_wrow += diff_check_fill(curwin, curwin->w_cursor.lnum); | 1072 curwin->w_wrow += diff_check_fill(curwin, curwin->w_cursor.lnum); |
1073 #endif | 1073 #endif |
1090 && curwin->w_height != 0 | 1090 && curwin->w_height != 0 |
1091 && curwin->w_cursor.lnum == curwin->w_topline | 1091 && curwin->w_cursor.lnum == curwin->w_topline |
1092 && width > 0 | 1092 && width > 0 |
1093 && curwin->w_width != 0) | 1093 && curwin->w_width != 0) |
1094 { | 1094 { |
1095 /* Cursor past end of screen. Happens with a single line that does | 1095 // Cursor past end of screen. Happens with a single line that does |
1096 * not fit on screen. Find a skipcol to show the text around the | 1096 // not fit on screen. Find a skipcol to show the text around the |
1097 * cursor. Avoid scrolling all the time. compute value of "extra": | 1097 // cursor. Avoid scrolling all the time. compute value of "extra": |
1098 * 1: Less than 'scrolloff' lines above | 1098 // 1: Less than 'scrolloff' lines above |
1099 * 2: Less than 'scrolloff' lines below | 1099 // 2: Less than 'scrolloff' lines below |
1100 * 3: both of them */ | 1100 // 3: both of them |
1101 extra = 0; | 1101 extra = 0; |
1102 if (curwin->w_skipcol + so * width > curwin->w_virtcol) | 1102 if (curwin->w_skipcol + so * width > curwin->w_virtcol) |
1103 extra = 1; | 1103 extra = 1; |
1104 /* Compute last display line of the buffer line that we want at the | 1104 // Compute last display line of the buffer line that we want at the |
1105 * bottom of the window. */ | 1105 // bottom of the window. |
1106 if (p_lines == 0) | 1106 if (p_lines == 0) |
1107 p_lines = plines_win(curwin, curwin->w_cursor.lnum, FALSE); | 1107 p_lines = plines_win(curwin, curwin->w_cursor.lnum, FALSE); |
1108 --p_lines; | 1108 --p_lines; |
1109 if (p_lines > curwin->w_wrow + so) | 1109 if (p_lines > curwin->w_wrow + so) |
1110 n = curwin->w_wrow + so; | 1110 n = curwin->w_wrow + so; |
1113 if ((colnr_T)n >= curwin->w_height + curwin->w_skipcol / width) | 1113 if ((colnr_T)n >= curwin->w_height + curwin->w_skipcol / width) |
1114 extra += 2; | 1114 extra += 2; |
1115 | 1115 |
1116 if (extra == 3 || p_lines < so * 2) | 1116 if (extra == 3 || p_lines < so * 2) |
1117 { | 1117 { |
1118 /* not enough room for 'scrolloff', put cursor in the middle */ | 1118 // not enough room for 'scrolloff', put cursor in the middle |
1119 n = curwin->w_virtcol / width; | 1119 n = curwin->w_virtcol / width; |
1120 if (n > curwin->w_height / 2) | 1120 if (n > curwin->w_height / 2) |
1121 n -= curwin->w_height / 2; | 1121 n -= curwin->w_height / 2; |
1122 else | 1122 else |
1123 n = 0; | 1123 n = 0; |
1124 /* don't skip more than necessary */ | 1124 // don't skip more than necessary |
1125 if (n > p_lines - curwin->w_height + 1) | 1125 if (n > p_lines - curwin->w_height + 1) |
1126 n = p_lines - curwin->w_height + 1; | 1126 n = p_lines - curwin->w_height + 1; |
1127 curwin->w_skipcol = n * width; | 1127 curwin->w_skipcol = n * width; |
1128 } | 1128 } |
1129 else if (extra == 1) | 1129 else if (extra == 1) |
1130 { | 1130 { |
1131 /* less then 'scrolloff' lines above, decrease skipcol */ | 1131 // less then 'scrolloff' lines above, decrease skipcol |
1132 extra = (curwin->w_skipcol + so * width - curwin->w_virtcol | 1132 extra = (curwin->w_skipcol + so * width - curwin->w_virtcol |
1133 + width - 1) / width; | 1133 + width - 1) / width; |
1134 if (extra > 0) | 1134 if (extra > 0) |
1135 { | 1135 { |
1136 if ((colnr_T)(extra * width) > curwin->w_skipcol) | 1136 if ((colnr_T)(extra * width) > curwin->w_skipcol) |
1138 curwin->w_skipcol -= extra * width; | 1138 curwin->w_skipcol -= extra * width; |
1139 } | 1139 } |
1140 } | 1140 } |
1141 else if (extra == 2) | 1141 else if (extra == 2) |
1142 { | 1142 { |
1143 /* less then 'scrolloff' lines below, increase skipcol */ | 1143 // less then 'scrolloff' lines below, increase skipcol |
1144 endcol = (n - curwin->w_height + 1) * width; | 1144 endcol = (n - curwin->w_height + 1) * width; |
1145 while (endcol > curwin->w_virtcol) | 1145 while (endcol > curwin->w_virtcol) |
1146 endcol -= width; | 1146 endcol -= width; |
1147 if (endcol > curwin->w_skipcol) | 1147 if (endcol > curwin->w_skipcol) |
1148 curwin->w_skipcol = endcol; | 1148 curwin->w_skipcol = endcol; |
1149 } | 1149 } |
1150 | 1150 |
1151 curwin->w_wrow -= curwin->w_skipcol / width; | 1151 curwin->w_wrow -= curwin->w_skipcol / width; |
1152 if (curwin->w_wrow >= curwin->w_height) | 1152 if (curwin->w_wrow >= curwin->w_height) |
1153 { | 1153 { |
1154 /* small window, make sure cursor is in it */ | 1154 // small window, make sure cursor is in it |
1155 extra = curwin->w_wrow - curwin->w_height + 1; | 1155 extra = curwin->w_wrow - curwin->w_height + 1; |
1156 curwin->w_skipcol += extra * width; | 1156 curwin->w_skipcol += extra * width; |
1157 curwin->w_wrow -= extra; | 1157 curwin->w_wrow -= extra; |
1158 } | 1158 } |
1159 | 1159 |
1167 curwin->w_skipcol = 0; | 1167 curwin->w_skipcol = 0; |
1168 if (prev_skipcol != curwin->w_skipcol) | 1168 if (prev_skipcol != curwin->w_skipcol) |
1169 redraw_later(NOT_VALID); | 1169 redraw_later(NOT_VALID); |
1170 | 1170 |
1171 #ifdef FEAT_SYN_HL | 1171 #ifdef FEAT_SYN_HL |
1172 /* Redraw when w_virtcol changes and 'cursorcolumn' is set */ | 1172 // Redraw when w_virtcol changes and 'cursorcolumn' is set |
1173 if (curwin->w_p_cuc && (curwin->w_valid & VALID_VIRTCOL) == 0 | 1173 if (curwin->w_p_cuc && (curwin->w_valid & VALID_VIRTCOL) == 0 |
1174 && !pum_visible()) | 1174 && !pum_visible()) |
1175 redraw_later(SOME_VALID); | 1175 redraw_later(SOME_VALID); |
1176 #endif | 1176 #endif |
1177 | 1177 |
1277 * Scroll the current window down by "line_count" logical lines. "CTRL-Y" | 1277 * Scroll the current window down by "line_count" logical lines. "CTRL-Y" |
1278 */ | 1278 */ |
1279 void | 1279 void |
1280 scrolldown( | 1280 scrolldown( |
1281 long line_count, | 1281 long line_count, |
1282 int byfold UNUSED) /* TRUE: count a closed fold as one line */ | 1282 int byfold UNUSED) // TRUE: count a closed fold as one line |
1283 { | 1283 { |
1284 long done = 0; /* total # of physical lines done */ | 1284 long done = 0; // total # of physical lines done |
1285 int wrow; | 1285 int wrow; |
1286 int moved = FALSE; | 1286 int moved = FALSE; |
1287 | 1287 |
1288 #ifdef FEAT_FOLDING | 1288 #ifdef FEAT_FOLDING |
1289 linenr_T first; | 1289 linenr_T first; |
1290 | 1290 |
1291 /* Make sure w_topline is at the first of a sequence of folded lines. */ | 1291 // Make sure w_topline is at the first of a sequence of folded lines. |
1292 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); | 1292 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); |
1293 #endif | 1293 #endif |
1294 validate_cursor(); /* w_wrow needs to be valid */ | 1294 validate_cursor(); // w_wrow needs to be valid |
1295 while (line_count-- > 0) | 1295 while (line_count-- > 0) |
1296 { | 1296 { |
1297 #ifdef FEAT_DIFF | 1297 #ifdef FEAT_DIFF |
1298 if (curwin->w_topfill < diff_check(curwin, curwin->w_topline) | 1298 if (curwin->w_topfill < diff_check(curwin, curwin->w_topline) |
1299 && curwin->w_topfill < curwin->w_height - 1) | 1299 && curwin->w_topfill < curwin->w_height - 1) |
1309 --curwin->w_topline; | 1309 --curwin->w_topline; |
1310 #ifdef FEAT_DIFF | 1310 #ifdef FEAT_DIFF |
1311 curwin->w_topfill = 0; | 1311 curwin->w_topfill = 0; |
1312 #endif | 1312 #endif |
1313 #ifdef FEAT_FOLDING | 1313 #ifdef FEAT_FOLDING |
1314 /* A sequence of folded lines only counts for one logical line */ | 1314 // A sequence of folded lines only counts for one logical line |
1315 if (hasFolding(curwin->w_topline, &first, NULL)) | 1315 if (hasFolding(curwin->w_topline, &first, NULL)) |
1316 { | 1316 { |
1317 ++done; | 1317 ++done; |
1318 if (!byfold) | 1318 if (!byfold) |
1319 line_count -= curwin->w_topline - first - 1; | 1319 line_count -= curwin->w_topline - first - 1; |
1322 } | 1322 } |
1323 else | 1323 else |
1324 #endif | 1324 #endif |
1325 done += PLINES_NOFILL(curwin->w_topline); | 1325 done += PLINES_NOFILL(curwin->w_topline); |
1326 } | 1326 } |
1327 --curwin->w_botline; /* approximate w_botline */ | 1327 --curwin->w_botline; // approximate w_botline |
1328 invalidate_botline(); | 1328 invalidate_botline(); |
1329 } | 1329 } |
1330 curwin->w_wrow += done; /* keep w_wrow updated */ | 1330 curwin->w_wrow += done; // keep w_wrow updated |
1331 curwin->w_cline_row += done; /* keep w_cline_row updated */ | 1331 curwin->w_cline_row += done; // keep w_cline_row updated |
1332 | 1332 |
1333 #ifdef FEAT_DIFF | 1333 #ifdef FEAT_DIFF |
1334 if (curwin->w_cursor.lnum == curwin->w_topline) | 1334 if (curwin->w_cursor.lnum == curwin->w_topline) |
1335 curwin->w_cline_row = 0; | 1335 curwin->w_cline_row = 0; |
1336 check_topfill(curwin, TRUE); | 1336 check_topfill(curwin, TRUE); |
1367 moved = TRUE; | 1367 moved = TRUE; |
1368 } | 1368 } |
1369 if (moved) | 1369 if (moved) |
1370 { | 1370 { |
1371 #ifdef FEAT_FOLDING | 1371 #ifdef FEAT_FOLDING |
1372 /* Move cursor to first line of closed fold. */ | 1372 // Move cursor to first line of closed fold. |
1373 foldAdjustCursor(); | 1373 foldAdjustCursor(); |
1374 #endif | 1374 #endif |
1375 coladvance(curwin->w_curswant); | 1375 coladvance(curwin->w_curswant); |
1376 } | 1376 } |
1377 } | 1377 } |
1380 * Scroll the current window up by "line_count" logical lines. "CTRL-E" | 1380 * Scroll the current window up by "line_count" logical lines. "CTRL-E" |
1381 */ | 1381 */ |
1382 void | 1382 void |
1383 scrollup( | 1383 scrollup( |
1384 long line_count, | 1384 long line_count, |
1385 int byfold UNUSED) /* TRUE: count a closed fold as one line */ | 1385 int byfold UNUSED) // TRUE: count a closed fold as one line |
1386 { | 1386 { |
1387 #if defined(FEAT_FOLDING) || defined(FEAT_DIFF) | 1387 #if defined(FEAT_FOLDING) || defined(FEAT_DIFF) |
1388 linenr_T lnum; | 1388 linenr_T lnum; |
1389 | 1389 |
1390 if ( | 1390 if ( |
1397 # ifdef FEAT_DIFF | 1397 # ifdef FEAT_DIFF |
1398 curwin->w_p_diff | 1398 curwin->w_p_diff |
1399 # endif | 1399 # endif |
1400 ) | 1400 ) |
1401 { | 1401 { |
1402 /* count each sequence of folded lines as one logical line */ | 1402 // count each sequence of folded lines as one logical line |
1403 lnum = curwin->w_topline; | 1403 lnum = curwin->w_topline; |
1404 while (line_count--) | 1404 while (line_count--) |
1405 { | 1405 { |
1406 # ifdef FEAT_DIFF | 1406 # ifdef FEAT_DIFF |
1407 if (curwin->w_topfill > 0) | 1407 if (curwin->w_topfill > 0) |
1419 # ifdef FEAT_DIFF | 1419 # ifdef FEAT_DIFF |
1420 curwin->w_topfill = diff_check_fill(curwin, lnum); | 1420 curwin->w_topfill = diff_check_fill(curwin, lnum); |
1421 # endif | 1421 # endif |
1422 } | 1422 } |
1423 } | 1423 } |
1424 /* approximate w_botline */ | 1424 // approximate w_botline |
1425 curwin->w_botline += lnum - curwin->w_topline; | 1425 curwin->w_botline += lnum - curwin->w_topline; |
1426 curwin->w_topline = lnum; | 1426 curwin->w_topline = lnum; |
1427 } | 1427 } |
1428 else | 1428 else |
1429 #endif | 1429 #endif |
1430 { | 1430 { |
1431 curwin->w_topline += line_count; | 1431 curwin->w_topline += line_count; |
1432 curwin->w_botline += line_count; /* approximate w_botline */ | 1432 curwin->w_botline += line_count; // approximate w_botline |
1433 } | 1433 } |
1434 | 1434 |
1435 if (curwin->w_topline > curbuf->b_ml.ml_line_count) | 1435 if (curwin->w_topline > curbuf->b_ml.ml_line_count) |
1436 curwin->w_topline = curbuf->b_ml.ml_line_count; | 1436 curwin->w_topline = curbuf->b_ml.ml_line_count; |
1437 if (curwin->w_botline > curbuf->b_ml.ml_line_count + 1) | 1437 if (curwin->w_botline > curbuf->b_ml.ml_line_count + 1) |
1441 check_topfill(curwin, FALSE); | 1441 check_topfill(curwin, FALSE); |
1442 #endif | 1442 #endif |
1443 | 1443 |
1444 #ifdef FEAT_FOLDING | 1444 #ifdef FEAT_FOLDING |
1445 if (hasAnyFolding(curwin)) | 1445 if (hasAnyFolding(curwin)) |
1446 /* Make sure w_topline is at the first of a sequence of folded lines. */ | 1446 // Make sure w_topline is at the first of a sequence of folded lines. |
1447 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); | 1447 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); |
1448 #endif | 1448 #endif |
1449 | 1449 |
1450 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); | 1450 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); |
1451 if (curwin->w_cursor.lnum < curwin->w_topline) | 1451 if (curwin->w_cursor.lnum < curwin->w_topline) |
1462 * Don't end up with too many filler lines in the window. | 1462 * Don't end up with too many filler lines in the window. |
1463 */ | 1463 */ |
1464 void | 1464 void |
1465 check_topfill( | 1465 check_topfill( |
1466 win_T *wp, | 1466 win_T *wp, |
1467 int down) /* when TRUE scroll down when not enough space */ | 1467 int down) // when TRUE scroll down when not enough space |
1468 { | 1468 { |
1469 int n; | 1469 int n; |
1470 | 1470 |
1471 if (wp->w_topfill > 0) | 1471 if (wp->w_topfill > 0) |
1472 { | 1472 { |
1527 && !can_fill | 1527 && !can_fill |
1528 #endif | 1528 #endif |
1529 ) | 1529 ) |
1530 return; | 1530 return; |
1531 | 1531 |
1532 validate_cursor(); /* w_wrow needs to be valid */ | 1532 validate_cursor(); // w_wrow needs to be valid |
1533 | 1533 |
1534 /* | 1534 /* |
1535 * Compute the row number of the last row of the cursor line | 1535 * Compute the row number of the last row of the cursor line |
1536 * and make sure it doesn't go off the screen. Make sure the cursor | 1536 * and make sure it doesn't go off the screen. Make sure the cursor |
1537 * doesn't go past 'scrolloff' lines from the screen end. | 1537 * doesn't go past 'scrolloff' lines from the screen end. |
1569 --curwin->w_topline; | 1569 --curwin->w_topline; |
1570 #endif | 1570 #endif |
1571 #ifdef FEAT_FOLDING | 1571 #ifdef FEAT_FOLDING |
1572 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); | 1572 (void)hasFolding(curwin->w_topline, &curwin->w_topline, NULL); |
1573 #endif | 1573 #endif |
1574 --curwin->w_botline; /* approximate w_botline */ | 1574 --curwin->w_botline; // approximate w_botline |
1575 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); | 1575 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); |
1576 } | 1576 } |
1577 } | 1577 } |
1578 | 1578 |
1579 /* | 1579 /* |
1590 && curwin->w_topfill == 0 | 1590 && curwin->w_topfill == 0 |
1591 #endif | 1591 #endif |
1592 ) | 1592 ) |
1593 return; | 1593 return; |
1594 | 1594 |
1595 validate_cursor(); /* w_wrow needs to be valid */ | 1595 validate_cursor(); // w_wrow needs to be valid |
1596 | 1596 |
1597 /* | 1597 /* |
1598 * Compute the row number of the first row of the cursor line | 1598 * Compute the row number of the first row of the cursor line |
1599 * and make sure it doesn't go off the screen. Make sure the cursor | 1599 * and make sure it doesn't go off the screen. Make sure the cursor |
1600 * doesn't go before 'scrolloff' lines from the screen start. | 1600 * doesn't go before 'scrolloff' lines from the screen start. |
1621 #ifdef FEAT_FOLDING | 1621 #ifdef FEAT_FOLDING |
1622 (void)hasFolding(curwin->w_topline, NULL, &curwin->w_topline); | 1622 (void)hasFolding(curwin->w_topline, NULL, &curwin->w_topline); |
1623 #endif | 1623 #endif |
1624 ++curwin->w_topline; | 1624 ++curwin->w_topline; |
1625 } | 1625 } |
1626 ++curwin->w_botline; /* approximate w_botline */ | 1626 ++curwin->w_botline; // approximate w_botline |
1627 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); | 1627 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); |
1628 } | 1628 } |
1629 } | 1629 } |
1630 | 1630 |
1631 /* | 1631 /* |
1638 topline_back(lineoff_T *lp) | 1638 topline_back(lineoff_T *lp) |
1639 { | 1639 { |
1640 #ifdef FEAT_DIFF | 1640 #ifdef FEAT_DIFF |
1641 if (lp->fill < diff_check_fill(curwin, lp->lnum)) | 1641 if (lp->fill < diff_check_fill(curwin, lp->lnum)) |
1642 { | 1642 { |
1643 /* Add a filler line. */ | 1643 // Add a filler line. |
1644 ++lp->fill; | 1644 ++lp->fill; |
1645 lp->height = 1; | 1645 lp->height = 1; |
1646 } | 1646 } |
1647 else | 1647 else |
1648 #endif | 1648 #endif |
1654 if (lp->lnum < 1) | 1654 if (lp->lnum < 1) |
1655 lp->height = MAXCOL; | 1655 lp->height = MAXCOL; |
1656 else | 1656 else |
1657 #ifdef FEAT_FOLDING | 1657 #ifdef FEAT_FOLDING |
1658 if (hasFolding(lp->lnum, &lp->lnum, NULL)) | 1658 if (hasFolding(lp->lnum, &lp->lnum, NULL)) |
1659 /* Add a closed fold */ | 1659 // Add a closed fold |
1660 lp->height = 1; | 1660 lp->height = 1; |
1661 else | 1661 else |
1662 #endif | 1662 #endif |
1663 lp->height = PLINES_NOFILL(lp->lnum); | 1663 lp->height = PLINES_NOFILL(lp->lnum); |
1664 } | 1664 } |
1674 botline_forw(lineoff_T *lp) | 1674 botline_forw(lineoff_T *lp) |
1675 { | 1675 { |
1676 #ifdef FEAT_DIFF | 1676 #ifdef FEAT_DIFF |
1677 if (lp->fill < diff_check_fill(curwin, lp->lnum + 1)) | 1677 if (lp->fill < diff_check_fill(curwin, lp->lnum + 1)) |
1678 { | 1678 { |
1679 /* Add a filler line. */ | 1679 // Add a filler line. |
1680 ++lp->fill; | 1680 ++lp->fill; |
1681 lp->height = 1; | 1681 lp->height = 1; |
1682 } | 1682 } |
1683 else | 1683 else |
1684 #endif | 1684 #endif |
1690 if (lp->lnum > curbuf->b_ml.ml_line_count) | 1690 if (lp->lnum > curbuf->b_ml.ml_line_count) |
1691 lp->height = MAXCOL; | 1691 lp->height = MAXCOL; |
1692 else | 1692 else |
1693 #ifdef FEAT_FOLDING | 1693 #ifdef FEAT_FOLDING |
1694 if (hasFolding(lp->lnum, NULL, &lp->lnum)) | 1694 if (hasFolding(lp->lnum, NULL, &lp->lnum)) |
1695 /* Add a closed fold */ | 1695 // Add a closed fold |
1696 lp->height = 1; | 1696 lp->height = 1; |
1697 else | 1697 else |
1698 #endif | 1698 #endif |
1699 lp->height = PLINES_NOFILL(lp->lnum); | 1699 lp->height = PLINES_NOFILL(lp->lnum); |
1700 } | 1700 } |
1742 { | 1742 { |
1743 int scrolled = 0; | 1743 int scrolled = 0; |
1744 int extra = 0; | 1744 int extra = 0; |
1745 int used; | 1745 int used; |
1746 int i; | 1746 int i; |
1747 linenr_T top; /* just above displayed lines */ | 1747 linenr_T top; // just above displayed lines |
1748 linenr_T bot; /* just below displayed lines */ | 1748 linenr_T bot; // just below displayed lines |
1749 linenr_T old_topline = curwin->w_topline; | 1749 linenr_T old_topline = curwin->w_topline; |
1750 #ifdef FEAT_DIFF | 1750 #ifdef FEAT_DIFF |
1751 linenr_T old_topfill = curwin->w_topfill; | 1751 linenr_T old_topfill = curwin->w_topfill; |
1752 #endif | 1752 #endif |
1753 linenr_T new_topline; | 1753 linenr_T new_topline; |
1762 * - (part of) the cursor line is moved off the screen or | 1762 * - (part of) the cursor line is moved off the screen or |
1763 * - moved at least 'scrolljump' lines and | 1763 * - moved at least 'scrolljump' lines and |
1764 * - at least 'scrolloff' lines above and below the cursor | 1764 * - at least 'scrolloff' lines above and below the cursor |
1765 */ | 1765 */ |
1766 validate_cheight(); | 1766 validate_cheight(); |
1767 used = curwin->w_cline_height; /* includes filler lines above */ | 1767 used = curwin->w_cline_height; // includes filler lines above |
1768 if (curwin->w_cursor.lnum < curwin->w_topline) | 1768 if (curwin->w_cursor.lnum < curwin->w_topline) |
1769 scrolled = used; | 1769 scrolled = used; |
1770 | 1770 |
1771 #ifdef FEAT_FOLDING | 1771 #ifdef FEAT_FOLDING |
1772 if (hasFolding(curwin->w_cursor.lnum, &top, &bot)) | 1772 if (hasFolding(curwin->w_cursor.lnum, &top, &bot)) |
1781 bot = curwin->w_cursor.lnum + 1; | 1781 bot = curwin->w_cursor.lnum + 1; |
1782 } | 1782 } |
1783 new_topline = top + 1; | 1783 new_topline = top + 1; |
1784 | 1784 |
1785 #ifdef FEAT_DIFF | 1785 #ifdef FEAT_DIFF |
1786 /* "used" already contains the number of filler lines above, don't add it | 1786 // "used" already contains the number of filler lines above, don't add it |
1787 * again. | 1787 // again. |
1788 * Hide filler lines above cursor line by adding them to "extra". */ | 1788 // Hide filler lines above cursor line by adding them to "extra". |
1789 extra += diff_check_fill(curwin, curwin->w_cursor.lnum); | 1789 extra += diff_check_fill(curwin, curwin->w_cursor.lnum); |
1790 #endif | 1790 #endif |
1791 | 1791 |
1792 /* | 1792 /* |
1793 * Check if the lines from "top" to "bot" fit in the window. If they do, | 1793 * Check if the lines from "top" to "bot" fit in the window. If they do, |
1795 */ | 1795 */ |
1796 while (top > 0) | 1796 while (top > 0) |
1797 { | 1797 { |
1798 #ifdef FEAT_FOLDING | 1798 #ifdef FEAT_FOLDING |
1799 if (hasFolding(top, &top, NULL)) | 1799 if (hasFolding(top, &top, NULL)) |
1800 /* count one logical line for a sequence of folded lines */ | 1800 // count one logical line for a sequence of folded lines |
1801 i = 1; | 1801 i = 1; |
1802 else | 1802 else |
1803 #endif | 1803 #endif |
1804 i = PLINES_NOFILL(top); | 1804 i = PLINES_NOFILL(top); |
1805 used += i; | 1805 used += i; |
1806 if (extra + i <= off && bot < curbuf->b_ml.ml_line_count) | 1806 if (extra + i <= off && bot < curbuf->b_ml.ml_line_count) |
1807 { | 1807 { |
1808 #ifdef FEAT_FOLDING | 1808 #ifdef FEAT_FOLDING |
1809 if (hasFolding(bot, NULL, &bot)) | 1809 if (hasFolding(bot, NULL, &bot)) |
1810 /* count one logical line for a sequence of folded lines */ | 1810 // count one logical line for a sequence of folded lines |
1811 ++used; | 1811 ++used; |
1812 else | 1812 else |
1813 #endif | 1813 #endif |
1814 used += plines(bot); | 1814 used += plines(bot); |
1815 } | 1815 } |
1878 { | 1878 { |
1879 #ifdef FEAT_DIFF | 1879 #ifdef FEAT_DIFF |
1880 wp->w_filler_rows = 0; | 1880 wp->w_filler_rows = 0; |
1881 #endif | 1881 #endif |
1882 if (used == 0) | 1882 if (used == 0) |
1883 wp->w_empty_rows = 0; /* single line that doesn't fit */ | 1883 wp->w_empty_rows = 0; // single line that doesn't fit |
1884 else | 1884 else |
1885 { | 1885 { |
1886 wp->w_empty_rows = wp->w_height - used; | 1886 wp->w_empty_rows = wp->w_height - used; |
1887 #ifdef FEAT_DIFF | 1887 #ifdef FEAT_DIFF |
1888 if (wp->w_botline <= wp->w_buffer->b_ml.ml_line_count) | 1888 if (wp->w_botline <= wp->w_buffer->b_ml.ml_line_count) |
1922 int fill_below_window; | 1922 int fill_below_window; |
1923 #endif | 1923 #endif |
1924 linenr_T old_botline = curwin->w_botline; | 1924 linenr_T old_botline = curwin->w_botline; |
1925 linenr_T old_valid = curwin->w_valid; | 1925 linenr_T old_valid = curwin->w_valid; |
1926 int old_empty_rows = curwin->w_empty_rows; | 1926 int old_empty_rows = curwin->w_empty_rows; |
1927 linenr_T cln; /* Cursor Line Number */ | 1927 linenr_T cln; // Cursor Line Number |
1928 long so = get_scrolloff_value(); | 1928 long so = get_scrolloff_value(); |
1929 | 1929 |
1930 cln = curwin->w_cursor.lnum; | 1930 cln = curwin->w_cursor.lnum; |
1931 if (set_topbot) | 1931 if (set_topbot) |
1932 { | 1932 { |
1958 curwin->w_valid &= ~(VALID_WROW|VALID_CROW); | 1958 curwin->w_valid &= ~(VALID_WROW|VALID_CROW); |
1959 } | 1959 } |
1960 else | 1960 else |
1961 validate_botline(); | 1961 validate_botline(); |
1962 | 1962 |
1963 /* The lines of the cursor line itself are always used. */ | 1963 // The lines of the cursor line itself are always used. |
1964 #ifdef FEAT_DIFF | 1964 #ifdef FEAT_DIFF |
1965 used = plines_nofill(cln); | 1965 used = plines_nofill(cln); |
1966 #else | 1966 #else |
1967 validate_cheight(); | 1967 validate_cheight(); |
1968 used = curwin->w_cline_height; | 1968 used = curwin->w_cline_height; |
1969 #endif | 1969 #endif |
1970 | 1970 |
1971 /* If the cursor is below botline, we will at least scroll by the height | 1971 // If the cursor is below botline, we will at least scroll by the height |
1972 * of the cursor line. Correct for empty lines, which are really part of | 1972 // of the cursor line. Correct for empty lines, which are really part of |
1973 * botline. */ | 1973 // botline. |
1974 if (cln >= curwin->w_botline) | 1974 if (cln >= curwin->w_botline) |
1975 { | 1975 { |
1976 scrolled = used; | 1976 scrolled = used; |
1977 if (cln == curwin->w_botline) | 1977 if (cln == curwin->w_botline) |
1978 scrolled -= curwin->w_empty_rows; | 1978 scrolled -= curwin->w_empty_rows; |
1999 - curwin->w_filler_rows; | 1999 - curwin->w_filler_rows; |
2000 #endif | 2000 #endif |
2001 | 2001 |
2002 while (loff.lnum > 1) | 2002 while (loff.lnum > 1) |
2003 { | 2003 { |
2004 /* Stop when scrolled nothing or at least "min_scroll", found "extra" | 2004 // Stop when scrolled nothing or at least "min_scroll", found "extra" |
2005 * context for 'scrolloff' and counted all lines below the window. */ | 2005 // context for 'scrolloff' and counted all lines below the window. |
2006 if ((((scrolled <= 0 || scrolled >= min_scroll) | 2006 if ((((scrolled <= 0 || scrolled >= min_scroll) |
2007 && extra >= (mouse_dragging > 0 ? mouse_dragging - 1 : so)) | 2007 && extra >= (mouse_dragging > 0 ? mouse_dragging - 1 : so)) |
2008 || boff.lnum + 1 > curbuf->b_ml.ml_line_count) | 2008 || boff.lnum + 1 > curbuf->b_ml.ml_line_count) |
2009 && loff.lnum <= curwin->w_botline | 2009 && loff.lnum <= curwin->w_botline |
2010 #ifdef FEAT_DIFF | 2010 #ifdef FEAT_DIFF |
2012 || loff.fill >= fill_below_window) | 2012 || loff.fill >= fill_below_window) |
2013 #endif | 2013 #endif |
2014 ) | 2014 ) |
2015 break; | 2015 break; |
2016 | 2016 |
2017 /* Add one line above */ | 2017 // Add one line above |
2018 topline_back(&loff); | 2018 topline_back(&loff); |
2019 if (loff.height == MAXCOL) | 2019 if (loff.height == MAXCOL) |
2020 used = MAXCOL; | 2020 used = MAXCOL; |
2021 else | 2021 else |
2022 used += loff.height; | 2022 used += loff.height; |
2027 && (loff.lnum > curwin->w_botline | 2027 && (loff.lnum > curwin->w_botline |
2028 || loff.fill <= fill_below_window) | 2028 || loff.fill <= fill_below_window) |
2029 #endif | 2029 #endif |
2030 ) | 2030 ) |
2031 { | 2031 { |
2032 /* Count screen lines that are below the window. */ | 2032 // Count screen lines that are below the window. |
2033 scrolled += loff.height; | 2033 scrolled += loff.height; |
2034 if (loff.lnum == curwin->w_botline | 2034 if (loff.lnum == curwin->w_botline |
2035 #ifdef FEAT_DIFF | 2035 #ifdef FEAT_DIFF |
2036 && loff.fill == 0 | 2036 && loff.fill == 0 |
2037 #endif | 2037 #endif |
2039 scrolled -= curwin->w_empty_rows; | 2039 scrolled -= curwin->w_empty_rows; |
2040 } | 2040 } |
2041 | 2041 |
2042 if (boff.lnum < curbuf->b_ml.ml_line_count) | 2042 if (boff.lnum < curbuf->b_ml.ml_line_count) |
2043 { | 2043 { |
2044 /* Add one line below */ | 2044 // Add one line below |
2045 botline_forw(&boff); | 2045 botline_forw(&boff); |
2046 used += boff.height; | 2046 used += boff.height; |
2047 if (used > curwin->w_height) | 2047 if (used > curwin->w_height) |
2048 break; | 2048 break; |
2049 if (extra < ( mouse_dragging > 0 ? mouse_dragging - 1 : so) | 2049 if (extra < ( mouse_dragging > 0 ? mouse_dragging - 1 : so) |
2055 || (boff.lnum + 1 == curwin->w_botline | 2055 || (boff.lnum + 1 == curwin->w_botline |
2056 && boff.fill > curwin->w_filler_rows) | 2056 && boff.fill > curwin->w_filler_rows) |
2057 #endif | 2057 #endif |
2058 ) | 2058 ) |
2059 { | 2059 { |
2060 /* Count screen lines that are below the window. */ | 2060 // Count screen lines that are below the window. |
2061 scrolled += boff.height; | 2061 scrolled += boff.height; |
2062 if (boff.lnum == curwin->w_botline | 2062 if (boff.lnum == curwin->w_botline |
2063 #ifdef FEAT_DIFF | 2063 #ifdef FEAT_DIFF |
2064 && boff.fill == 0 | 2064 && boff.fill == 0 |
2065 #endif | 2065 #endif |
2068 } | 2068 } |
2069 } | 2069 } |
2070 } | 2070 } |
2071 } | 2071 } |
2072 | 2072 |
2073 /* curwin->w_empty_rows is larger, no need to scroll */ | 2073 // curwin->w_empty_rows is larger, no need to scroll |
2074 if (scrolled <= 0) | 2074 if (scrolled <= 0) |
2075 line_count = 0; | 2075 line_count = 0; |
2076 /* more than a screenfull, don't scroll but redraw */ | 2076 // more than a screenfull, don't scroll but redraw |
2077 else if (used > curwin->w_height) | 2077 else if (used > curwin->w_height) |
2078 line_count = used; | 2078 line_count = used; |
2079 /* scroll minimal number of lines */ | 2079 // scroll minimal number of lines |
2080 else | 2080 else |
2081 { | 2081 { |
2082 line_count = 0; | 2082 line_count = 0; |
2083 #ifdef FEAT_DIFF | 2083 #ifdef FEAT_DIFF |
2084 boff.fill = curwin->w_topfill; | 2084 boff.fill = curwin->w_topfill; |
2088 { | 2088 { |
2089 botline_forw(&boff); | 2089 botline_forw(&boff); |
2090 i += boff.height; | 2090 i += boff.height; |
2091 ++line_count; | 2091 ++line_count; |
2092 } | 2092 } |
2093 if (i < scrolled) /* below curwin->w_botline, don't scroll */ | 2093 if (i < scrolled) // below curwin->w_botline, don't scroll |
2094 line_count = 9999; | 2094 line_count = 9999; |
2095 } | 2095 } |
2096 | 2096 |
2097 /* | 2097 /* |
2098 * Scroll up if the cursor is off the bottom of the screen a bit. | 2098 * Scroll up if the cursor is off the bottom of the screen a bit. |
2149 used = plines(loff.lnum); | 2149 used = plines(loff.lnum); |
2150 #endif | 2150 #endif |
2151 topline = loff.lnum; | 2151 topline = loff.lnum; |
2152 while (topline > 1) | 2152 while (topline > 1) |
2153 { | 2153 { |
2154 if (below <= above) /* add a line below the cursor first */ | 2154 if (below <= above) // add a line below the cursor first |
2155 { | 2155 { |
2156 if (boff.lnum < curbuf->b_ml.ml_line_count) | 2156 if (boff.lnum < curbuf->b_ml.ml_line_count) |
2157 { | 2157 { |
2158 botline_forw(&boff); | 2158 botline_forw(&boff); |
2159 used += boff.height; | 2159 used += boff.height; |
2161 break; | 2161 break; |
2162 below += boff.height; | 2162 below += boff.height; |
2163 } | 2163 } |
2164 else | 2164 else |
2165 { | 2165 { |
2166 ++below; /* count a "~" line */ | 2166 ++below; // count a "~" line |
2167 if (atend) | 2167 if (atend) |
2168 ++used; | 2168 ++used; |
2169 } | 2169 } |
2170 } | 2170 } |
2171 | 2171 |
2172 if (below > above) /* add a line above the cursor */ | 2172 if (below > above) // add a line above the cursor |
2173 { | 2173 { |
2174 topline_back(&loff); | 2174 topline_back(&loff); |
2175 if (loff.height == MAXCOL) | 2175 if (loff.height == MAXCOL) |
2176 used = MAXCOL; | 2176 used = MAXCOL; |
2177 else | 2177 else |
2206 * When called topline must be valid! | 2206 * When called topline must be valid! |
2207 */ | 2207 */ |
2208 void | 2208 void |
2209 cursor_correct(void) | 2209 cursor_correct(void) |
2210 { | 2210 { |
2211 int above = 0; /* screen lines above topline */ | 2211 int above = 0; // screen lines above topline |
2212 linenr_T topline; | 2212 linenr_T topline; |
2213 int below = 0; /* screen lines below botline */ | 2213 int below = 0; // screen lines below botline |
2214 linenr_T botline; | 2214 linenr_T botline; |
2215 int above_wanted, below_wanted; | 2215 int above_wanted, below_wanted; |
2216 linenr_T cln; /* Cursor Line Number */ | 2216 linenr_T cln; // Cursor Line Number |
2217 int max_off; | 2217 int max_off; |
2218 long so = get_scrolloff_value(); | 2218 long so = get_scrolloff_value(); |
2219 | 2219 |
2220 /* | 2220 /* |
2221 * How many lines we would like to have above/below the cursor depends on | 2221 * How many lines we would like to have above/below the cursor depends on |
2265 * - the lines from the top is past the lines from the bottom | 2265 * - the lines from the top is past the lines from the bottom |
2266 */ | 2266 */ |
2267 topline = curwin->w_topline; | 2267 topline = curwin->w_topline; |
2268 botline = curwin->w_botline - 1; | 2268 botline = curwin->w_botline - 1; |
2269 #ifdef FEAT_DIFF | 2269 #ifdef FEAT_DIFF |
2270 /* count filler lines as context */ | 2270 // count filler lines as context |
2271 above = curwin->w_topfill; | 2271 above = curwin->w_topfill; |
2272 below = curwin->w_filler_rows; | 2272 below = curwin->w_filler_rows; |
2273 #endif | 2273 #endif |
2274 while ((above < above_wanted || below < below_wanted) && topline < botline) | 2274 while ((above < above_wanted || below < below_wanted) && topline < botline) |
2275 { | 2275 { |
2290 ++above; | 2290 ++above; |
2291 else | 2291 else |
2292 #endif | 2292 #endif |
2293 above += PLINES_NOFILL(topline); | 2293 above += PLINES_NOFILL(topline); |
2294 #ifdef FEAT_DIFF | 2294 #ifdef FEAT_DIFF |
2295 /* Count filler lines below this line as context. */ | 2295 // Count filler lines below this line as context. |
2296 if (topline < botline) | 2296 if (topline < botline) |
2297 above += diff_check_fill(curwin, topline + 1); | 2297 above += diff_check_fill(curwin, topline + 1); |
2298 #endif | 2298 #endif |
2299 ++topline; | 2299 ++topline; |
2300 } | 2300 } |
2335 int retval = OK; | 2335 int retval = OK; |
2336 lineoff_T loff; | 2336 lineoff_T loff; |
2337 linenr_T old_topline = curwin->w_topline; | 2337 linenr_T old_topline = curwin->w_topline; |
2338 long so = get_scrolloff_value(); | 2338 long so = get_scrolloff_value(); |
2339 | 2339 |
2340 if (curbuf->b_ml.ml_line_count == 1) /* nothing to do */ | 2340 if (curbuf->b_ml.ml_line_count == 1) // nothing to do |
2341 { | 2341 { |
2342 beep_flush(); | 2342 beep_flush(); |
2343 return FAIL; | 2343 return FAIL; |
2344 } | 2344 } |
2345 | 2345 |
2372 #endif | 2372 #endif |
2373 if (dir == FORWARD) | 2373 if (dir == FORWARD) |
2374 { | 2374 { |
2375 if (ONE_WINDOW && p_window > 0 && p_window < Rows - 1) | 2375 if (ONE_WINDOW && p_window > 0 && p_window < Rows - 1) |
2376 { | 2376 { |
2377 /* Vi compatible scrolling */ | 2377 // Vi compatible scrolling |
2378 if (p_window <= 2) | 2378 if (p_window <= 2) |
2379 ++curwin->w_topline; | 2379 ++curwin->w_topline; |
2380 else | 2380 else |
2381 curwin->w_topline += p_window - 2; | 2381 curwin->w_topline += p_window - 2; |
2382 if (curwin->w_topline > curbuf->b_ml.ml_line_count) | 2382 if (curwin->w_topline > curbuf->b_ml.ml_line_count) |
2383 curwin->w_topline = curbuf->b_ml.ml_line_count; | 2383 curwin->w_topline = curbuf->b_ml.ml_line_count; |
2384 curwin->w_cursor.lnum = curwin->w_topline; | 2384 curwin->w_cursor.lnum = curwin->w_topline; |
2385 } | 2385 } |
2386 else if (curwin->w_botline > curbuf->b_ml.ml_line_count) | 2386 else if (curwin->w_botline > curbuf->b_ml.ml_line_count) |
2387 { | 2387 { |
2388 /* at end of file */ | 2388 // at end of file |
2389 curwin->w_topline = curbuf->b_ml.ml_line_count; | 2389 curwin->w_topline = curbuf->b_ml.ml_line_count; |
2390 #ifdef FEAT_DIFF | 2390 #ifdef FEAT_DIFF |
2391 curwin->w_topfill = 0; | 2391 curwin->w_topfill = 0; |
2392 #endif | 2392 #endif |
2393 curwin->w_valid &= ~(VALID_WROW|VALID_CROW); | 2393 curwin->w_valid &= ~(VALID_WROW|VALID_CROW); |
2394 } | 2394 } |
2395 else | 2395 else |
2396 { | 2396 { |
2397 /* For the overlap, start with the line just below the window | 2397 // For the overlap, start with the line just below the window |
2398 * and go upwards. */ | 2398 // and go upwards. |
2399 loff.lnum = curwin->w_botline; | 2399 loff.lnum = curwin->w_botline; |
2400 #ifdef FEAT_DIFF | 2400 #ifdef FEAT_DIFF |
2401 loff.fill = diff_check_fill(curwin, loff.lnum) | 2401 loff.fill = diff_check_fill(curwin, loff.lnum) |
2402 - curwin->w_filler_rows; | 2402 - curwin->w_filler_rows; |
2403 #endif | 2403 #endif |
2410 curwin->w_cursor.lnum = curwin->w_topline; | 2410 curwin->w_cursor.lnum = curwin->w_topline; |
2411 curwin->w_valid &= ~(VALID_WCOL|VALID_CHEIGHT|VALID_WROW| | 2411 curwin->w_valid &= ~(VALID_WCOL|VALID_CHEIGHT|VALID_WROW| |
2412 VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP); | 2412 VALID_CROW|VALID_BOTLINE|VALID_BOTLINE_AP); |
2413 } | 2413 } |
2414 } | 2414 } |
2415 else /* dir == BACKWARDS */ | 2415 else // dir == BACKWARDS |
2416 { | 2416 { |
2417 #ifdef FEAT_DIFF | 2417 #ifdef FEAT_DIFF |
2418 if (curwin->w_topline == 1) | 2418 if (curwin->w_topline == 1) |
2419 { | 2419 { |
2420 /* Include max number of filler lines */ | 2420 // Include max number of filler lines |
2421 max_topfill(); | 2421 max_topfill(); |
2422 continue; | 2422 continue; |
2423 } | 2423 } |
2424 #endif | 2424 #endif |
2425 if (ONE_WINDOW && p_window > 0 && p_window < Rows - 1) | 2425 if (ONE_WINDOW && p_window > 0 && p_window < Rows - 1) |
2426 { | 2426 { |
2427 /* Vi compatible scrolling (sort of) */ | 2427 // Vi compatible scrolling (sort of) |
2428 if (p_window <= 2) | 2428 if (p_window <= 2) |
2429 --curwin->w_topline; | 2429 --curwin->w_topline; |
2430 else | 2430 else |
2431 curwin->w_topline -= p_window - 2; | 2431 curwin->w_topline -= p_window - 2; |
2432 if (curwin->w_topline < 1) | 2432 if (curwin->w_topline < 1) |
2435 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) | 2435 if (curwin->w_cursor.lnum > curbuf->b_ml.ml_line_count) |
2436 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; | 2436 curwin->w_cursor.lnum = curbuf->b_ml.ml_line_count; |
2437 continue; | 2437 continue; |
2438 } | 2438 } |
2439 | 2439 |
2440 /* Find the line at the top of the window that is going to be the | 2440 // Find the line at the top of the window that is going to be the |
2441 * line at the bottom of the window. Make sure this results in | 2441 // line at the bottom of the window. Make sure this results in |
2442 * the same line as before doing CTRL-F. */ | 2442 // the same line as before doing CTRL-F. |
2443 loff.lnum = curwin->w_topline - 1; | 2443 loff.lnum = curwin->w_topline - 1; |
2444 #ifdef FEAT_DIFF | 2444 #ifdef FEAT_DIFF |
2445 loff.fill = diff_check_fill(curwin, loff.lnum + 1) | 2445 loff.fill = diff_check_fill(curwin, loff.lnum + 1) |
2446 - curwin->w_topfill; | 2446 - curwin->w_topfill; |
2447 #endif | 2447 #endif |
2458 botline_topline(&loff); | 2458 botline_topline(&loff); |
2459 #endif | 2459 #endif |
2460 } | 2460 } |
2461 curwin->w_cursor.lnum = loff.lnum; | 2461 curwin->w_cursor.lnum = loff.lnum; |
2462 | 2462 |
2463 /* Find the line just above the new topline to get the right line | 2463 // Find the line just above the new topline to get the right line |
2464 * at the bottom of the window. */ | 2464 // at the bottom of the window. |
2465 n = 0; | 2465 n = 0; |
2466 while (n <= curwin->w_height && loff.lnum >= 1) | 2466 while (n <= curwin->w_height && loff.lnum >= 1) |
2467 { | 2467 { |
2468 topline_back(&loff); | 2468 topline_back(&loff); |
2469 if (loff.height == MAXCOL) | 2469 if (loff.height == MAXCOL) |
2470 n = MAXCOL; | 2470 n = MAXCOL; |
2471 else | 2471 else |
2472 n += loff.height; | 2472 n += loff.height; |
2473 } | 2473 } |
2474 if (loff.lnum < 1) /* at begin of file */ | 2474 if (loff.lnum < 1) // at begin of file |
2475 { | 2475 { |
2476 curwin->w_topline = 1; | 2476 curwin->w_topline = 1; |
2477 #ifdef FEAT_DIFF | 2477 #ifdef FEAT_DIFF |
2478 max_topfill(); | 2478 max_topfill(); |
2479 #endif | 2479 #endif |
2480 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); | 2480 curwin->w_valid &= ~(VALID_WROW|VALID_CROW|VALID_BOTLINE); |
2481 } | 2481 } |
2482 else | 2482 else |
2483 { | 2483 { |
2484 /* Go two lines forward again. */ | 2484 // Go two lines forward again. |
2485 #ifdef FEAT_DIFF | 2485 #ifdef FEAT_DIFF |
2486 topline_botline(&loff); | 2486 topline_botline(&loff); |
2487 #endif | 2487 #endif |
2488 botline_forw(&loff); | 2488 botline_forw(&loff); |
2489 botline_forw(&loff); | 2489 botline_forw(&loff); |
2490 #ifdef FEAT_DIFF | 2490 #ifdef FEAT_DIFF |
2491 botline_topline(&loff); | 2491 botline_topline(&loff); |
2492 #endif | 2492 #endif |
2493 #ifdef FEAT_FOLDING | 2493 #ifdef FEAT_FOLDING |
2494 /* We're at the wrong end of a fold now. */ | 2494 // We're at the wrong end of a fold now. |
2495 (void)hasFolding(loff.lnum, &loff.lnum, NULL); | 2495 (void)hasFolding(loff.lnum, &loff.lnum, NULL); |
2496 #endif | 2496 #endif |
2497 | 2497 |
2498 /* Always scroll at least one line. Avoid getting stuck on | 2498 // Always scroll at least one line. Avoid getting stuck on |
2499 * very long lines. */ | 2499 // very long lines. |
2500 if (loff.lnum >= curwin->w_topline | 2500 if (loff.lnum >= curwin->w_topline |
2501 #ifdef FEAT_DIFF | 2501 #ifdef FEAT_DIFF |
2502 && (loff.lnum > curwin->w_topline | 2502 && (loff.lnum > curwin->w_topline |
2503 || loff.fill >= curwin->w_topfill) | 2503 || loff.fill >= curwin->w_topfill) |
2504 #endif | 2504 #endif |
2505 ) | 2505 ) |
2506 { | 2506 { |
2507 #ifdef FEAT_DIFF | 2507 #ifdef FEAT_DIFF |
2508 /* First try using the maximum number of filler lines. If | 2508 // First try using the maximum number of filler lines. If |
2509 * that's not enough, backup one line. */ | 2509 // that's not enough, backup one line. |
2510 loff.fill = curwin->w_topfill; | 2510 loff.fill = curwin->w_topfill; |
2511 if (curwin->w_topfill < diff_check_fill(curwin, | 2511 if (curwin->w_topfill < diff_check_fill(curwin, |
2512 curwin->w_topline)) | 2512 curwin->w_topline)) |
2513 max_topfill(); | 2513 max_topfill(); |
2514 if (curwin->w_topfill == loff.fill) | 2514 if (curwin->w_topfill == loff.fill) |
2599 #else | 2599 #else |
2600 lp->height = plines(lp->lnum); | 2600 lp->height = plines(lp->lnum); |
2601 #endif | 2601 #endif |
2602 h1 = lp->height; | 2602 h1 = lp->height; |
2603 if (h1 > min_height) | 2603 if (h1 > min_height) |
2604 return; /* no overlap */ | 2604 return; // no overlap |
2605 | 2605 |
2606 loff0 = *lp; | 2606 loff0 = *lp; |
2607 if (dir > 0) | 2607 if (dir > 0) |
2608 botline_forw(lp); | 2608 botline_forw(lp); |
2609 else | 2609 else |
2610 topline_back(lp); | 2610 topline_back(lp); |
2611 h2 = lp->height; | 2611 h2 = lp->height; |
2612 if (h2 == MAXCOL || h2 + h1 > min_height) | 2612 if (h2 == MAXCOL || h2 + h1 > min_height) |
2613 { | 2613 { |
2614 *lp = loff0; /* no overlap */ | 2614 *lp = loff0; // no overlap |
2615 return; | 2615 return; |
2616 } | 2616 } |
2617 | 2617 |
2618 loff1 = *lp; | 2618 loff1 = *lp; |
2619 if (dir > 0) | 2619 if (dir > 0) |
2621 else | 2621 else |
2622 topline_back(lp); | 2622 topline_back(lp); |
2623 h3 = lp->height; | 2623 h3 = lp->height; |
2624 if (h3 == MAXCOL || h3 + h2 > min_height) | 2624 if (h3 == MAXCOL || h3 + h2 > min_height) |
2625 { | 2625 { |
2626 *lp = loff0; /* no overlap */ | 2626 *lp = loff0; // no overlap |
2627 return; | 2627 return; |
2628 } | 2628 } |
2629 | 2629 |
2630 loff2 = *lp; | 2630 loff2 = *lp; |
2631 if (dir > 0) | 2631 if (dir > 0) |
2632 botline_forw(lp); | 2632 botline_forw(lp); |
2633 else | 2633 else |
2634 topline_back(lp); | 2634 topline_back(lp); |
2635 h4 = lp->height; | 2635 h4 = lp->height; |
2636 if (h4 == MAXCOL || h4 + h3 + h2 > min_height || h3 + h2 + h1 > min_height) | 2636 if (h4 == MAXCOL || h4 + h3 + h2 > min_height || h3 + h2 + h1 > min_height) |
2637 *lp = loff1; /* 1 line overlap */ | 2637 *lp = loff1; // 1 line overlap |
2638 else | 2638 else |
2639 *lp = loff2; /* 2 lines overlap */ | 2639 *lp = loff2; // 2 lines overlap |
2640 return; | 2640 return; |
2641 } | 2641 } |
2642 | 2642 |
2643 /* | 2643 /* |
2644 * Scroll 'scroll' lines up or down. | 2644 * Scroll 'scroll' lines up or down. |
2812 # endif | 2812 # endif |
2813 curwin->w_cursor.lnum -= n; | 2813 curwin->w_cursor.lnum -= n; |
2814 } | 2814 } |
2815 } | 2815 } |
2816 # ifdef FEAT_FOLDING | 2816 # ifdef FEAT_FOLDING |
2817 /* Move cursor to first line of closed fold. */ | 2817 // Move cursor to first line of closed fold. |
2818 foldAdjustCursor(); | 2818 foldAdjustCursor(); |
2819 # endif | 2819 # endif |
2820 #ifdef FEAT_DIFF | 2820 #ifdef FEAT_DIFF |
2821 check_topfill(curwin, !flag); | 2821 check_topfill(curwin, !flag); |
2822 #endif | 2822 #endif |
2844 */ | 2844 */ |
2845 VIsual_select = VIsual_active = 0; | 2845 VIsual_select = VIsual_active = 0; |
2846 FOR_ALL_WINDOWS(curwin) | 2846 FOR_ALL_WINDOWS(curwin) |
2847 { | 2847 { |
2848 curbuf = curwin->w_buffer; | 2848 curbuf = curwin->w_buffer; |
2849 /* skip original window and windows with 'noscrollbind' */ | 2849 // skip original window and windows with 'noscrollbind' |
2850 if (curwin != old_curwin && curwin->w_p_crb) | 2850 if (curwin != old_curwin && curwin->w_p_crb) |
2851 { | 2851 { |
2852 # ifdef FEAT_DIFF | 2852 # ifdef FEAT_DIFF |
2853 if (curwin->w_p_diff) | 2853 if (curwin->w_p_diff) |
2854 curwin->w_cursor.lnum = | 2854 curwin->w_cursor.lnum = |
2859 curwin->w_cursor.col = col; | 2859 curwin->w_cursor.col = col; |
2860 curwin->w_cursor.coladd = coladd; | 2860 curwin->w_cursor.coladd = coladd; |
2861 curwin->w_curswant = curswant; | 2861 curwin->w_curswant = curswant; |
2862 curwin->w_set_curswant = set_curswant; | 2862 curwin->w_set_curswant = set_curswant; |
2863 | 2863 |
2864 /* Make sure the cursor is in a valid position. Temporarily set | 2864 // Make sure the cursor is in a valid position. Temporarily set |
2865 * "restart_edit" to allow the cursor to be beyond the EOL. */ | 2865 // "restart_edit" to allow the cursor to be beyond the EOL. |
2866 restart_edit_save = restart_edit; | 2866 restart_edit_save = restart_edit; |
2867 restart_edit = TRUE; | 2867 restart_edit = TRUE; |
2868 check_cursor(); | 2868 check_cursor(); |
2869 # ifdef FEAT_SYN_HL | 2869 # ifdef FEAT_SYN_HL |
2870 if (curwin->w_p_cul || curwin->w_p_cuc) | 2870 if (curwin->w_p_cul || curwin->w_p_cuc) |
2871 validate_cursor(); | 2871 validate_cursor(); |
2872 # endif | 2872 # endif |
2873 restart_edit = restart_edit_save; | 2873 restart_edit = restart_edit_save; |
2874 /* Correct cursor for multi-byte character. */ | 2874 // Correct cursor for multi-byte character. |
2875 if (has_mbyte) | 2875 if (has_mbyte) |
2876 mb_adjust_cursor(); | 2876 mb_adjust_cursor(); |
2877 redraw_later(VALID); | 2877 redraw_later(VALID); |
2878 | 2878 |
2879 /* Only scroll when 'scrollbind' hasn't done this. */ | 2879 // Only scroll when 'scrollbind' hasn't done this. |
2880 if (!curwin->w_p_scb) | 2880 if (!curwin->w_p_scb) |
2881 update_topline(); | 2881 update_topline(); |
2882 curwin->w_redr_status = TRUE; | 2882 curwin->w_redr_status = TRUE; |
2883 } | 2883 } |
2884 } | 2884 } |