From 6538d0aadb32625e2d6969c835ebd061cad8a780 Mon Sep 17 00:00:00 2001 From: debaditya <82204129+DebadityaHait@users.noreply.github.com> Date: Mon, 3 Aug 2026 19:18:33 +0530 Subject: [PATCH] fix(ui2): retain substitute confirmation highlight with nohlsearch #41067 Problem: ui2 clears the substitute confirmation match when it updates its prompt buffer with hlsearch disabled. Solution: Only invalidate the match highlight when the current buffer changes. --- src/nvim/change.c | 6 ++++-- test/functional/ui/cmdline2_spec.lua | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/nvim/change.c b/src/nvim/change.c index 67b0d40143..6eba9ceed4 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -142,8 +142,10 @@ void changed(buf_T *buf) } buf_inc_changedtick(buf); - // If a pattern is highlighted, the position may now be invalid. - Search.hl_match = false; + // A match highlight can only be invalidated by changes to the current buffer. + if (buf == curbuf) { + Search.hl_match = false; + } } /// Internal part of changed(), no user interaction. diff --git a/test/functional/ui/cmdline2_spec.lua b/test/functional/ui/cmdline2_spec.lua index 7564416192..2077985419 100644 --- a/test/functional/ui/cmdline2_spec.lua +++ b/test/functional/ui/cmdline2_spec.lua @@ -201,6 +201,24 @@ describe('cmdline2', function() screen:expect_unchanged(true) end) + it('keeps the confirmation match highlighted with nohlsearch #41039', function() + exec('call setline(1, "test test") | set nohlsearch') + feed('/te') + screen:expect([[ + test ^test | + {1:~ }|*12 + /te | + ]]) + + feed(':%s/te/t/gc') + screen:expect([[ + {2:te}st test | + {1:~ }|*11 + {6:replace with t? (y)es/(n)o/(a)ll/(q)uit/(l)ast/scroll}| + {6: up(^E)/down(^Y)}^ | + ]]) + end) + it('dialog position is adjusted for toggled non-pum wildmenu', function() exec([[ set wildmode=list:full,full wildoptions-=pum