summaryrefslogtreecommitdiffstats
path: root/src/edit.c
diff options
context:
space:
mode:
authorLuuk van Baal <luukvbaal@gmail.com>2023-06-02 14:16:35 +0100
committerBram Moolenaar <Bram@vim.org>2023-06-02 14:16:35 +0100
commita109f39ef54bc3894768170f02c1b6ac56164488 (patch)
tree2991683d08efbba19c489753c0c606c247860252 /src/edit.c
parent47eec6716b8621fd43bac8ecc9c19089df26705e (diff)
patch 9.0.1599: Cursor not adjusted when 'splitkeep' is not "cursor"v9.0.1599
Problem: Cursor not adjusted when near top or bottom of window and 'splitkeep' is not "cursor". Solution: Move boundary checks to outer cursor move functions, inner functions should only return valid cursor positions. (Luuk van Baal, closes #12480)
Diffstat (limited to 'src/edit.c')
-rw-r--r--src/edit.c39
1 files changed, 18 insertions, 21 deletions
diff --git a/src/edit.c b/src/edit.c
index a882d67feb..d1b70160f5 100644
--- a/src/edit.c
+++ b/src/edit.c
@@ -2755,17 +2755,12 @@ oneleft(void)
/*
* 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
+ void
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 or the count is
- // larger than the line number and '-' is in 'cpoptions'
- if (lnum <= 1 || (n >= lnum && vim_strchr(p_cpo, CPO_MINUS) != NULL))
- return 0;
if (n >= lnum)
lnum = 1;
else
@@ -2798,7 +2793,6 @@ cursor_up_inner(win_T *wp, long n)
lnum -= n;
wp->w_cursor.lnum = lnum;
- return lnum;
}
int
@@ -2806,8 +2800,13 @@ cursor_up(
long n,
int upd_topline) // When TRUE: update topline
{
- if (n > 0 && cursor_up_inner(curwin, n) == 0)
+ // This fails if the cursor is already in the first line or the count is
+ // larger than the line number and '-' is in 'cpoptions'
+ linenr_T lnum = curwin->w_cursor.lnum;
+ if (n > 0 && (lnum <= 1
+ || (n >= lnum && vim_strchr(p_cpo, CPO_MINUS) != NULL)))
return FAIL;
+ cursor_up_inner(curwin, n);
// try to advance to the column we want to be at
coladvance(curwin->w_curswant);
@@ -2821,23 +2820,13 @@ cursor_up(
/*
* 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
+ void
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;
-#ifdef FEAT_FOLDING
- // Move to last line of fold, will fail if it's the end-of-file.
- (void)hasFoldingWin(wp, lnum, NULL, &lnum, TRUE, NULL);
-#endif
- // This fails if the cursor is already in the last line or would move
- // beyond the last line and '-' is in 'cpoptions'
- if (lnum >= line_count
- || (lnum + n > line_count && vim_strchr(p_cpo, CPO_MINUS) != NULL))
- return FAIL;
if (lnum + n >= line_count)
lnum = line_count;
else
@@ -2849,6 +2838,7 @@ cursor_down_inner(win_T *wp, long n)
// count each sequence of folded lines as one logical line
while (n--)
{
+ // Move to last line of fold, will fail if it's the end-of-file.
if (hasFoldingWin(wp, lnum, NULL, &last, TRUE, NULL))
lnum = last + 1;
else
@@ -2864,7 +2854,6 @@ cursor_down_inner(win_T *wp, long n)
lnum += n;
wp->w_cursor.lnum = lnum;
- return lnum;
}
/*
@@ -2875,8 +2864,16 @@ cursor_down(
long n,
int upd_topline) // When TRUE: update topline
{
- if (n > 0 && cursor_down_inner(curwin, n) == 0)
+ linenr_T lnum = curwin->w_cursor.lnum;
+ linenr_T line_count = curwin->w_buffer->b_ml.ml_line_count;
+ // This fails if the cursor is already in the last line or would move
+ // beyond the last line and '-' is in 'cpoptions'
+ if (n > 0
+ && (lnum >= line_count
+ || (lnum + n > line_count
+ && vim_strchr(p_cpo, CPO_MINUS) != NULL)))
return FAIL;
+ cursor_down_inner(curwin, n);
// try to advance to the column we want to be at
coladvance(curwin->w_curswant);