From b8b21015400656114cb689d399526a7a98ef5526 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 10 Dec 2022 19:23:24 +0800 Subject: [PATCH] fix(api): set correct curbuf when temporarily changing curwin (cherry picked from commit 44f22adb22032a176199bc75316e307378684ade) --- src/nvim/api/window.c | 4 ++++ test/functional/api/window_spec.lua | 33 +++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/src/nvim/api/window.c b/src/nvim/api/window.c index 08dcc113da..eb089fbc05 100644 --- a/src/nvim/api/window.c +++ b/src/nvim/api/window.c @@ -162,9 +162,11 @@ void nvim_win_set_height(Window window, Integer height, Error *err) win_T *savewin = curwin; curwin = win; + curbuf = curwin->w_buffer; try_start(); win_setheight((int)height); curwin = savewin; + curbuf = curwin->w_buffer; try_end(err); } @@ -207,9 +209,11 @@ void nvim_win_set_width(Window window, Integer width, Error *err) win_T *savewin = curwin; curwin = win; + curbuf = curwin->w_buffer; try_start(); win_setwidth((int)width); curwin = savewin; + curbuf = curwin->w_buffer; try_end(err); } diff --git a/test/functional/api/window_spec.lua b/test/functional/api/window_spec.lua index 901d24327c..362aed4838 100644 --- a/test/functional/api/window_spec.lua +++ b/test/functional/api/window_spec.lua @@ -7,6 +7,7 @@ local clear, nvim, curbuf, curbuf_contents, window, curwin, eq, neq, helpers.tabpage local poke_eventloop = helpers.poke_eventloop local curwinmeths = helpers.curwinmeths +local exec = helpers.exec local funcs = helpers.funcs local request = helpers.request local NIL = helpers.NIL @@ -201,6 +202,22 @@ describe('API/win', function() window('set_height', nvim('list_wins')[2], 2) eq(2, window('get_height', nvim('list_wins')[2])) end) + + it('do not cause ml_get errors with foldmethod=expr #19989', function() + insert([[ + aaaaa + bbbbb + ccccc]]) + command('set foldmethod=expr') + exec([[ + new + let w = nvim_get_current_win() + wincmd w + call nvim_win_set_height(w, 5) + ]]) + feed('l') + eq('', meths.get_vvar('errmsg')) + end) end) describe('{get,set}_width', function() @@ -215,6 +232,22 @@ describe('API/win', function() window('set_width', nvim('list_wins')[2], 2) eq(2, window('get_width', nvim('list_wins')[2])) end) + + it('do not cause ml_get errors with foldmethod=expr #19989', function() + insert([[ + aaaaa + bbbbb + ccccc]]) + command('set foldmethod=expr') + exec([[ + vnew + let w = nvim_get_current_win() + wincmd w + call nvim_win_set_width(w, 5) + ]]) + feed('l') + eq('', meths.get_vvar('errmsg')) + end) end) describe('{get,set,del}_var', function()