comparison src/window.c @ 30535:04df44c52d65 v9.0.0603

patch 9.0.0603: with 'nosplitscroll' folds are not handled correctly Commit: https://github.com/vim/vim/commit/7c1cbb6cd437c6e0c3ccc05840cc931108b4a60a Author: Luuk van Baal <luukvbaal@gmail.com> Date: Tue Sep 27 12:31:15 2022 +0100 patch 9.0.0603: with 'nosplitscroll' folds are not handled correctly Problem: With 'nosplitscroll' folds are not handled correctly. Solution: Take care of closed folds when moving the cursor. (Luuk van Baal, closes #11234)
author Bram Moolenaar <Bram@vim.org>
date Tue, 27 Sep 2022 13:45:04 +0200
parents 6fa498af368d
children 66de6909e102
comparison
equal deleted inserted replaced
30534:e2cfe68129e6 30535:04df44c52d65
6349 } 6349 }
6350 6350
6351 /* 6351 /*
6352 * Handle scroll position for 'nosplitscroll'. Replaces scroll_to_fraction() 6352 * Handle scroll position for 'nosplitscroll'. Replaces scroll_to_fraction()
6353 * call from win_new_height(). Instead we iterate over all windows in a 6353 * call from win_new_height(). Instead we iterate over all windows in a
6354 * tabpage and calculate the new scroll/cursor position. 6354 * tabpage and calculate the new scroll position.
6355 * TODO: Ensure this also works with wrapped lines. 6355 * TODO: Ensure this also works with wrapped lines.
6356 * Requires topline to be able to be set to a bufferline with some 6356 * Requires topline to be able to be set to a bufferline with some
6357 * offset(row-wise scrolling/smoothscroll). 6357 * offset(row-wise scrolling/smoothscroll).
6358 */ 6358 */
6359 static void 6359 static void
6360 win_fix_scroll(int resize) 6360 win_fix_scroll(int resize)
6361 { 6361 {
6362 win_T *wp; 6362 int diff;
6363 linenr_T lnum; 6363 win_T *wp;
6364 linenr_T lnum;
6364 6365
6365 skip_update_topline = TRUE; // avoid scrolling in curs_columns() 6366 skip_update_topline = TRUE; // avoid scrolling in curs_columns()
6366 FOR_ALL_WINDOWS(wp) 6367 FOR_ALL_WINDOWS(wp)
6367 { 6368 {
6368 // Skip when window height has not changed. 6369 // Skip when window height has not changed.
6369 if (wp->w_height != wp->w_prev_height) 6370 if (wp->w_height != wp->w_prev_height)
6370 { 6371 {
6371 // Determine botline needed to avoid scrolling and set cursor. 6372 // If window has moved update botline to keep the same screenlines.
6372 if (wp->w_winrow != wp->w_prev_winrow) 6373 if (wp->w_winrow != wp->w_prev_winrow)
6373 { 6374 {
6374 lnum = wp->w_cursor.lnum; 6375 lnum = wp->w_cursor.lnum;
6375 wp->w_cursor.lnum = MIN(wp->w_buffer->b_ml.ml_line_count, 6376 diff = (wp->w_winrow - wp->w_prev_winrow)
6376 wp->w_botline - 1 + (wp->w_winrow - wp->w_prev_winrow) 6377 + (wp->w_height - wp->w_prev_height);
6377 + (wp->w_height - wp->w_prev_height)); 6378 wp->w_cursor.lnum = wp->w_botline - 1;
6379 // Add difference in height and row to botline.
6380 if (diff > 0)
6381 cursor_down_inner(wp, diff);
6382 else
6383 cursor_up_inner(wp, -diff);
6378 // Bring the new cursor position to the bottom of the screen. 6384 // Bring the new cursor position to the bottom of the screen.
6379 wp->w_fraction = FRACTION_MULT; 6385 wp->w_fraction = FRACTION_MULT;
6380 scroll_to_fraction(wp, wp->w_prev_height); 6386 scroll_to_fraction(wp, wp->w_prev_height);
6381 wp->w_cursor.lnum = lnum; 6387 wp->w_cursor.lnum = lnum;
6382 } 6388 }
6403 * If we are not in normal mode, scroll to make valid instead. 6409 * If we are not in normal mode, scroll to make valid instead.
6404 */ 6410 */
6405 static void 6411 static void
6406 win_fix_cursor(int normal) 6412 win_fix_cursor(int normal)
6407 { 6413 {
6408 win_T *wp = curwin; 6414 long so = get_scrolloff_value();
6409 long so = get_scrolloff_value(); 6415 win_T *wp = curwin;
6410 linenr_T nlnum = 0; 6416 linenr_T nlnum = 0;
6417 linenr_T lnum = wp->w_cursor.lnum;
6418 linenr_T bot;
6419 linenr_T top;
6411 6420
6412 if (wp->w_buffer->b_ml.ml_line_count < wp->w_height) 6421 if (wp->w_buffer->b_ml.ml_line_count < wp->w_height)
6413 return; 6422 return;
6414 #ifdef FEAT_CMDWIN 6423 #ifdef FEAT_CMDWIN
6415 if (skip_win_fix_cursor) 6424 if (skip_win_fix_cursor)
6416 return; 6425 return;
6417 #endif 6426 #endif
6418 6427 // Determine valid cursor range.
6419 so = MIN(wp->w_height / 2, so); 6428 so = MIN(wp->w_height / 2, so);
6420 // Check if cursor position is above topline or below botline. 6429 wp->w_cursor.lnum = wp->w_topline;
6421 if (wp->w_cursor.lnum < (wp->w_topline + so) && wp->w_topline != 1) 6430 top = cursor_down_inner(wp, so);
6422 nlnum = MIN(wp->w_topline + so, wp->w_buffer->b_ml.ml_line_count); 6431 wp->w_cursor.lnum = wp->w_botline - 1;
6423 else if (wp->w_cursor.lnum > (wp->w_botline - so - 1) 6432 bot = cursor_up_inner(wp, so);
6424 && (wp->w_botline - wp->w_buffer->b_ml.ml_line_count) != 1) 6433 // Check if cursor position is above or below valid cursor range.
6425 nlnum = MAX(wp->w_botline - so - 1, 1); 6434 if (lnum > bot && (wp->w_botline - wp->w_buffer->b_ml.ml_line_count) != 1)
6426 // If cursor was invalid scroll or change cursor. 6435 nlnum = bot;
6427 if (nlnum) 6436 else if (lnum < top && wp->w_topline != 1)
6428 { 6437 nlnum = (so == wp->w_height / 2) ? bot : top;
6429 if (normal) 6438
6430 { // Make sure cursor is closer to topline than botline. 6439 wp->w_cursor.lnum = lnum;
6431 if (so == wp->w_height / 2 6440
6432 && nlnum - wp->w_topline > wp->w_botline - 1 - nlnum) 6441 if (nlnum) // Cursor is invalid for current scroll position.
6433 nlnum--; 6442 {
6434 setmark('\''); // save cursor position 6443 if (normal) // Save to jumplist and set cursor to avoid scrolling.
6435 wp->w_cursor.lnum = nlnum; // change to avoid scrolling 6444 {
6445 setmark('\'');
6446 wp->w_cursor.lnum = nlnum;
6436 curs_columns(TRUE); // validate w_wrow 6447 curs_columns(TRUE); // validate w_wrow
6437 } 6448 }
6438 else 6449 else // Scroll instead when not in normal mode.
6439 { // Ensure cursor stays visible if we are not in normal mode. 6450 {
6440 wp->w_fraction = 0.5 * FRACTION_MULT; 6451 wp->w_fraction = 0.5 * FRACTION_MULT;
6441 scroll_to_fraction(wp, wp->w_prev_height); 6452 scroll_to_fraction(wp, wp->w_prev_height);
6442 validate_botline_win(curwin); 6453 validate_botline_win(curwin);
6443 } 6454 }
6444 } 6455 }