aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/undo.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/undo.c')
-rw-r--r--src/nvim/undo.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/nvim/undo.c b/src/nvim/undo.c
index 329af8acdd..36b629b0b5 100644
--- a/src/nvim/undo.c
+++ b/src/nvim/undo.c
@@ -212,8 +212,11 @@ static void u_check(int newhead_may_be_NULL) {
*/
int u_save_cursor(void)
{
- return u_save((linenr_T)(curwin->w_cursor.lnum - 1),
- (linenr_T)(curwin->w_cursor.lnum + 1));
+ linenr_T cur = curwin->w_cursor.lnum;
+ linenr_T top = cur > 0 ? cur - 1 : 0;
+ linenr_T bot = cur + 1;
+
+ return u_save(top, bot);
}
/*
@@ -227,10 +230,9 @@ int u_save(linenr_T top, linenr_T bot)
if (undo_off)
return OK;
- if (top > curbuf->b_ml.ml_line_count
- || top >= bot
- || bot > curbuf->b_ml.ml_line_count + 1)
+ if (top >= bot || bot > (curbuf->b_ml.ml_line_count + 1)) {
return FAIL; /* rely on caller to do error messages */
+ }
if (top + 2 == bot)
u_saveline((linenr_T)(top + 1));