aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/api/window.c3
-rw-r--r--test/functional/api/window_spec.lua23
2 files changed, 26 insertions, 0 deletions
diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c
index abfa0dc20b..b02e5b958d 100644
--- a/src/nvim/api/window.c
+++ b/src/nvim/api/window.c
@@ -93,6 +93,9 @@ void nvim_win_set_cursor(Window window, ArrayOf(Integer, 2) pos, Error *err)
// When column is out of range silently correct it.
check_cursor_col_win(win);
+ // Make sure we stick in this column.
+ win->w_curswant = (colnr_T)col;
+
// make sure cursor is in visible range even if win != curwin
update_topline_win(win);
diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua
index 8a65d3f71e..d404ef5426 100644
--- a/test/functional/api/window_spec.lua
+++ b/test/functional/api/window_spec.lua
@@ -108,6 +108,29 @@ describe('api/win', function()
neq(win, curwin())
end)
+ it('remembers what column it wants to be in', function()
+ insert("first line")
+ feed('o<esc>')
+ insert("second line")
+
+ feed('gg')
+ wait() -- let nvim process the 'gg' command
+
+ -- cursor position is at beginning
+ local win = curwin()
+ eq({1, 0}, window('get_cursor', win))
+
+ -- move cursor to column 5
+ window('set_cursor', win, {1, 5})
+
+ -- move down a line
+ feed('j')
+ wait() -- let nvim process the 'j' command
+
+ -- cursor is still in column 5
+ eq({2, 5}, window('get_cursor', win))
+ end)
+
end)
describe('{get,set}_height', function()