aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Hotham <david.hotham@metaswitch.com>2018-06-25 01:14:55 +0100
committerJustin M. Keyes <justinkz@gmail.com>2018-06-25 02:14:55 +0200
commit1cbc8301897c09d381074397b82450f81d7854be (patch)
tree0587f26749468a6872ab4724b23ba451898b0517
parente475476d1041a6632cfb9d3fff48051fcef0fbf5 (diff)
downloadrneovim-1cbc8301897c09d381074397b82450f81d7854be.tar.gz
rneovim-1cbc8301897c09d381074397b82450f81d7854be.tar.bz2
rneovim-1cbc8301897c09d381074397b82450f81d7854be.zip
API: nvim_win_set_cursor: set curswant #8613
Fixes #8591
-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()