From 9af03bcd47127a416aa6a125590b75adb5f53c3c Mon Sep 17 00:00:00 2001 From: Omar El Halabi Date: Fri, 10 Nov 2023 05:20:26 +0100 Subject: [PATCH] fix(options): do not change inccommand during preview (#25462) --- src/nvim/optionstr.c | 3 +++ test/functional/ui/inccommand_spec.lua | 28 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/nvim/optionstr.c b/src/nvim/optionstr.c index 7aea47cfff..be76688e92 100644 --- a/src/nvim/optionstr.c +++ b/src/nvim/optionstr.c @@ -1569,6 +1569,9 @@ const char *did_set_iconstring(optset_T *args) /// The 'inccommand' option is changed. const char *did_set_inccommand(optset_T *args FUNC_ATTR_UNUSED) { + if (cmdpreview) { + return e_invarg; + } return did_set_opt_strings(p_icm, p_icm_values, false); } diff --git a/test/functional/ui/inccommand_spec.lua b/test/functional/ui/inccommand_spec.lua index c9e004289d..3ee67a710c 100644 --- a/test/functional/ui/inccommand_spec.lua +++ b/test/functional/ui/inccommand_spec.lua @@ -3167,3 +3167,31 @@ it("with 'inccommand' typing :filter doesn't segfault or leak memory #19057", fu feed('i') assert_alive() end) + +it("'inccommand' cannot be changed during preview #23136", function() + clear() + local screen = Screen.new(30, 6) + common_setup(screen, 'nosplit', 'foo\nbar\nbaz') + source([[ + function! IncCommandToggle() + let prev = &inccommand + + if &inccommand ==# 'split' + set inccommand=nosplit + elseif &inccommand ==# 'nosplit' + set inccommand=split + elseif &inccommand ==# '' + set inccommand=nosplit + else + throw 'unknown inccommand' + endif + + return " \" + endfun + + cnoremap IncCommandToggle() + ]]) + + feed(':%s/foo/bar') + assert_alive() +end)