From 13f3bef685bfa209f6ff0ad1915a9a5aa63588e2 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 18 Oct 2023 09:26:09 +0800 Subject: [PATCH] fix(move): check the correct buffer (cherry picked from commit 56ffab5522b2b30e86a17e975c2e005f7f603f3d) --- src/nvim/move.c | 2 +- test/functional/ui/inccommand_spec.lua | 30 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/nvim/move.c b/src/nvim/move.c index 5d8136107e..0b81f34805 100644 --- a/src/nvim/move.c +++ b/src/nvim/move.c @@ -166,7 +166,7 @@ void update_topline(win_T *wp) old_topfill = wp->w_topfill; // If the buffer is empty, always set topline to 1. - if (buf_is_empty(curbuf)) { // special case - file is empty + if (buf_is_empty(wp->w_buffer)) { // special case - file is empty if (wp->w_topline != 1) { redraw_later(wp, UPD_NOT_VALID); } diff --git a/test/functional/ui/inccommand_spec.lua b/test/functional/ui/inccommand_spec.lua index 7f05f0f901..217a713c93 100644 --- a/test/functional/ui/inccommand_spec.lua +++ b/test/functional/ui/inccommand_spec.lua @@ -3087,6 +3087,36 @@ it(':substitute with inccommand works properly if undo is not synced #20029', fu baz]]) end) +it(':substitute with inccommand does not unexpectedly change viewport #25697', function() + clear() + local screen = Screen.new(45, 5) + common_setup(screen, 'nosplit', long_multiline_text) + command('vnew | tabnew | tabclose') + screen:expect([[ + ^ │£ m n | + {15:~ }│t œ ¥ | + {15:~ }│ | + {11:[No Name] }{10:[No Name] [+] }| + | + ]]) + feed(':s/') + screen:expect([[ + │£ m n | + {15:~ }│t œ ¥ | + {15:~ }│ | + {11:[No Name] }{10:[No Name] [+] }| + :s/^ | + ]]) + feed('') + screen:expect([[ + ^ │£ m n | + {15:~ }│t œ ¥ | + {15:~ }│ | + {11:[No Name] }{10:[No Name] [+] }| + | + ]]) +end) + it('long :%s/ with inccommand does not collapse cmdline', function() local screen = Screen.new(10,5) clear()