diff options
author | Björn Linse <bjorn.linse@gmail.com> | 2019-04-08 12:26:30 +0200 |
---|---|---|
committer | Björn Linse <bjorn.linse@gmail.com> | 2019-04-08 12:39:08 +0200 |
commit | 344c69b66b19c76a0a7e9f07f591f063317943d7 (patch) | |
tree | ba7c3a976abc2be1a032c03923164ff6fef79bf7 | |
parent | 11bf89e3b58be1dd534b4ea49b1988150cf7d4b8 (diff) | |
download | rneovim-344c69b66b19c76a0a7e9f07f591f063317943d7.tar.gz rneovim-344c69b66b19c76a0a7e9f07f591f063317943d7.tar.bz2 rneovim-344c69b66b19c76a0a7e9f07f591f063317943d7.zip |
api/window: validate cursor in nvim_win_set_buf
validate_cursor() is called regularly, but only for the current window.
When changing the buffer for a non-current window, we need to invoke it
in the context of that window.
-rw-r--r-- | src/nvim/api/window.c | 4 | ||||
-rw-r--r-- | test/functional/ui/float_spec.lua | 60 |
2 files changed, 64 insertions, 0 deletions
diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index a68ae805e8..01cb9a6847 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -67,6 +67,10 @@ void nvim_win_set_buf(Window window, Buffer buffer, Error *err) buffer); } + // If window is not current, state logic will not validate its cursor. + // So do it now. + validate_cursor(); + restore_win(save_curwin, save_curtab, false); } diff --git a/test/functional/ui/float_spec.lua b/test/functional/ui/float_spec.lua index 4a89345ee5..b248bd8f6f 100644 --- a/test/functional/ui/float_spec.lua +++ b/test/functional/ui/float_spec.lua @@ -550,6 +550,66 @@ describe('floating windows', function() end end) + it('validates cursor even when window is not entered', function() + screen:try_resize(30,5) + command("set nowrap") + insert([[some text that is wider than the window]]) + if multigrid then + screen:expect([[ + ## grid 1 + [2:------------------------------]| + [2:------------------------------]| + [2:------------------------------]| + [2:------------------------------]| + | + ## grid 2 + that is wider than the windo^w | + {0:~ }| + {0:~ }| + {0:~ }| + ]]) + else + screen:expect([[ + that is wider than the windo^w | + {0:~ }| + {0:~ }| + {0:~ }| + | + ]]) + end + + local buf = meths.create_buf(false,true) + meths.buf_set_lines(buf, 0, -1, true, {'some floaty text'}) + meths.open_win(buf, false, {relative='editor', width=20, height=1, row=3, col=1}) + if multigrid then + screen:expect{grid=[[ + ## grid 1 + [2:------------------------------]| + [2:------------------------------]| + [2:------------------------------]| + [2:------------------------------]| + | + ## grid 2 + that is wider than the windo^w | + {0:~ }| + {0:~ }| + {0:~ }| + ## grid 4 + {1:some floaty text }| + ]], float_pos={ + [4] = {{id = 1002}, "NW", 1, 3, 1, true} + }} + else + screen:expect([[ + that is wider than the windo^w | + {0:~ }| + {0:~ }| + {0:~}{1:some floaty text }{0: }| + | + ]]) + end + end) + if multigrid then pending("supports second UI without multigrid", function() local session2 = helpers.connect(eval('v:servername')) |