aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsander2 <sanderbosma@gmail.com>2017-04-21 15:45:51 +0200
committerJustin M. Keyes <justinkz@gmail.com>2017-04-21 15:45:51 +0200
commitf50e03f2e35cf4bee8cedb2c95bf9619f3b57bc2 (patch)
tree82101fa9b63fe270ccb958df52a7d76d6a2ec640
parenta396874da0efaeb7def5e26afab9ae1c980510a0 (diff)
downloadrneovim-f50e03f2e35cf4bee8cedb2c95bf9619f3b57bc2.tar.gz
rneovim-f50e03f2e35cf4bee8cedb2c95bf9619f3b57bc2.tar.bz2
rneovim-f50e03f2e35cf4bee8cedb2c95bf9619f3b57bc2.zip
ex_cmds.c: Fix bug in ex_z (#6557)
vim-patch:8.0.0571
-rw-r--r--src/nvim/ex_cmds.c12
-rw-r--r--test/functional/ex_cmds/print_commands_spec.lua12
2 files changed, 21 insertions, 3 deletions
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index 117ef6a507..7726e0fc6d 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -2877,8 +2877,11 @@ void ex_z(exarg_T *eap)
if (end > curbuf->b_ml.ml_line_count)
end = curbuf->b_ml.ml_line_count;
- if (curs > curbuf->b_ml.ml_line_count)
+ if (curs > curbuf->b_ml.ml_line_count) {
curs = curbuf->b_ml.ml_line_count;
+ } else if (curs < 1) {
+ curs = 1;
+ }
for (i = start; i <= end; i++) {
if (minus && i == lnum) {
@@ -2898,8 +2901,11 @@ void ex_z(exarg_T *eap)
}
}
- curwin->w_cursor.lnum = curs;
- ex_no_reprint = TRUE;
+ if (curwin->w_cursor.lnum != curs) {
+ curwin->w_cursor.lnum = curs;
+ curwin->w_cursor.col = 0;
+ }
+ ex_no_reprint = true;
}
/*
diff --git a/test/functional/ex_cmds/print_commands_spec.lua b/test/functional/ex_cmds/print_commands_spec.lua
new file mode 100644
index 0000000000..98c0f74635
--- /dev/null
+++ b/test/functional/ex_cmds/print_commands_spec.lua
@@ -0,0 +1,12 @@
+local helpers = require('test.functional.helpers')(after_each)
+local clear, eq, command, funcs =
+ helpers.clear, helpers.eq, helpers.command, helpers.funcs
+
+describe(':z^', function()
+ before_each(clear)
+
+ it('correctly sets the cursor after :z^', function()
+ command('z^')
+ eq(1, funcs.line('.'))
+ end)
+end)