feat(window/ui): add splitkeep option (#19243)

vim-patch:9.0.0445: when opening/closing window text moves up/down

Problem:    When opening/closing window text moves up/down.
Solution:   Add the 'splitscroll' option.  When off text will keep its
            position as much as possible.
29ab524358

vim-patch:9.0.0455: a few problems with 'splitscroll'

Problem:    A few problems with 'splitscroll'.
Solution:   Fix 'splitscroll' problems. (Luuk van Baal, closes vim/vim#11117)
5ed391708a

vim-patch:9.0.0461: 'scroll' is not always updated

Problem:    'scroll' is not always updated.
Solution:   Call win_init_size() at the right place.
470a14140b

vim-patch:9.0.0465: cursor moves when cmdwin is closed when 'splitscroll' is off

Problem:    Cursor moves when cmdwin is closed when 'splitscroll' is off.
Solution:   Temporarily set 'splitscroll' when jumping back to the original
            window. (closes vim/vim#11128)
e697d48890

vim-patch:9.0.0469: cursor moves if cmdwin is closed when 'splitscroll' is off

Problem:    Cursor moves if cmdwin is closed when 'splitscroll' is off.
Solution:   Skip win_fix_cursor if called when cmdwin is open or closing.
            (Luuk van Baal, closes vim/vim#11134)
3735f11050

vim-patch:9.0.0478: test for 'splitscroll' takes too much time

Problem:    Test for 'splitscroll' takes too much time.
Solution:   Only test some of the combinations. (Luuk van Baal, closes vim/vim#11139)
594f9e09cd

vim-patch:9.0.0486: text scrolled with 'nosplitscroll', autocmd win and help

Problem:    Text scrolled with 'nosplitscroll', autocmd win opened and help
            window closed.
Solution:   Skip win_fix_scroll() in more situations. (Luuk van Baal,
            closes vim/vim#11150)
d5bc762dea

vim-patch:9.0.0505: various problems with 'nosplitscroll'

Problem:    Various problems with 'nosplitscroll'.
Solution:   Fix 'nosplitscroll' problems. (Luuk van Baal, closes vim/vim#11166)
faf1d412f5

vim-patch:9.0.0555: scrolling with 'nosplitscroll' in callback changing curwin

Problem:    Scrolling with 'nosplitscroll' in callback changing curwin.
Solution:   Invalidate w_cline_row in the right place. (Luuk van Baal,
            closes vim/vim#11185)
20e58561ab

vim-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 vim/vim#11234)
7c1cbb6cd4

vim-patch:9.0.0605: dump file missing

Problem:    Dump file missing.
Solution:   Add the missing dump file. (issue vim/vim#11234)
439a2ba174

vim-patch:9.0.0647: the 'splitscroll' option is not a good name

Problem:    The 'splitscroll' option is not a good name.
Solution:   Rename 'splitscroll' to 'splitkeep' and make it a string option,
            also supporting "topline". (Luuk van Baal, closes vim/vim#11258)
13ece2ae1d

vim-patch:9.0.0667: ml_get error when 'splitkeep' is "screen"

Problem:    ml_get error when 'splitkeep' is "screen". (Marius Gedminas)
Solution:   Check the botline is not too large. (Luuk van Baal,
            closes vim/vim#11293, closes vim/vim#11292)
346823d3e5
This commit is contained in:
luukvbaal
2022-10-06 08:57:52 +02:00
committed by GitHub
parent 4bfbac05c9
commit 5acf52e19b
15 changed files with 733 additions and 80 deletions

View File

@@ -2541,97 +2541,112 @@ int oneleft(void)
return OK;
}
/// @oaram upd_topline When true: update topline
/// Move the cursor up "n" lines in window "wp".
/// Takes care of closed folds.
/// Returns the new cursor line or zero for failure.
linenr_T cursor_up_inner(win_T *wp, long n)
{
linenr_T lnum = wp->w_cursor.lnum;
// This fails if the cursor is already in the first line.
if (lnum <= 1) {
return 0;
}
if (n >= lnum) {
lnum = 1;
} else if (hasAnyFolding(wp)) {
// Count each sequence of folded lines as one logical line.
// go to the start of the current fold
(void)hasFoldingWin(wp, lnum, &lnum, NULL, true, NULL);
while (n--) {
// move up one line
lnum--;
if (lnum <= 1) {
break;
}
// If we entered a fold, move to the beginning, unless in
// Insert mode or when 'foldopen' contains "all": it will open
// in a moment.
if (n > 0 || !((State & MODE_INSERT) || (fdo_flags & FDO_ALL))) {
(void)hasFoldingWin(wp, lnum, &lnum, NULL, true, NULL);
}
}
if (lnum < 1) {
lnum = 1;
}
} else {
lnum -= (linenr_T)n;
}
wp->w_cursor.lnum = lnum;
return lnum;
}
/// @param upd_topline When true: update topline
int cursor_up(long n, int upd_topline)
{
linenr_T lnum;
if (n > 0) {
lnum = curwin->w_cursor.lnum;
// This fails if the cursor is already in the first line.
if (lnum <= 1) {
return FAIL;
}
if (n >= lnum) {
lnum = 1;
} else if (hasAnyFolding(curwin)) {
// Count each sequence of folded lines as one logical line.
// go to the start of the current fold
(void)hasFolding(lnum, &lnum, NULL);
while (n--) {
// move up one line
lnum--;
if (lnum <= 1) {
break;
}
// If we entered a fold, move to the beginning, unless in
// Insert mode or when 'foldopen' contains "all": it will open
// in a moment.
if (n > 0 || !((State & MODE_INSERT) || (fdo_flags & FDO_ALL))) {
(void)hasFolding(lnum, &lnum, NULL);
}
}
if (lnum < 1) {
lnum = 1;
}
} else {
lnum -= (linenr_T)n;
}
curwin->w_cursor.lnum = lnum;
if (n > 0 && cursor_up_inner(curwin, n) == 0) {
return FAIL;
}
// try to advance to the column we want to be at
coladvance(curwin->w_curswant);
if (upd_topline) {
update_topline(curwin); // make sure curwin->w_topline is valid
update_topline(curwin); // make sure curwin->w_topline is valid
}
return OK;
}
/// Cursor down a number of logical lines.
///
/// Move the cursor down "n" lines in window "wp".
/// Takes care of closed folds.
/// Returns the new cursor line or zero for failure.
linenr_T cursor_down_inner(win_T *wp, long n)
{
linenr_T lnum = wp->w_cursor.lnum;
linenr_T line_count = wp->w_buffer->b_ml.ml_line_count;
// Move to last line of fold, will fail if it's the end-of-file.
(void)hasFoldingWin(wp, lnum, NULL, &lnum, true, NULL);
// This fails if the cursor is already in the last line.
if (lnum >= line_count) {
return FAIL;
}
if (lnum + n >= line_count) {
lnum = line_count;
} else if (hasAnyFolding(wp)) {
linenr_T last;
// count each sequence of folded lines as one logical line
while (n--) {
if (hasFoldingWin(wp, lnum, NULL, &last, true, NULL)) {
lnum = last + 1;
} else {
lnum++;
}
if (lnum >= line_count) {
break;
}
}
if (lnum > line_count) {
lnum = line_count;
}
} else {
lnum += (linenr_T)n;
}
wp->w_cursor.lnum = lnum;
return lnum;
}
/// @param upd_topline When true: update topline
int cursor_down(long n, int upd_topline)
{
linenr_T lnum;
if (n > 0) {
lnum = curwin->w_cursor.lnum;
// Move to last line of fold, will fail if it's the end-of-file.
(void)hasFolding(lnum, NULL, &lnum);
// This fails if the cursor is already in the last line.
if (lnum >= curbuf->b_ml.ml_line_count) {
return FAIL;
}
if (lnum + n >= curbuf->b_ml.ml_line_count) {
lnum = curbuf->b_ml.ml_line_count;
} else if (hasAnyFolding(curwin)) {
linenr_T last;
// count each sequence of folded lines as one logical line
while (n--) {
if (hasFolding(lnum, NULL, &last)) {
lnum = last + 1;
} else {
lnum++;
}
if (lnum >= curbuf->b_ml.ml_line_count) {
break;
}
}
if (lnum > curbuf->b_ml.ml_line_count) {
lnum = curbuf->b_ml.ml_line_count;
}
} else {
lnum += (linenr_T)n;
}
curwin->w_cursor.lnum = lnum;
if (n > 0 && cursor_down_inner(curwin, n) == 0) {
return FAIL;
}
// try to advance to the column we want to be at