From dadaa7fcade459ebd1fef2ee4eada1a389ea036d Mon Sep 17 00:00:00 2001 From: Sean Dewar <6256228+seandewar@users.noreply.github.com> Date: Sat, 22 Aug 2026 15:19:16 +0100 Subject: [PATCH] fix(ui2): offset extmarks copied to pager by srow #41425 Problem: wrong end_row when copying extmarks to the pager buffer when expanding a message. Results in incorrect highlights or errors such as "invalid `end_col` out of range". Solution: don't forget to offset end_row by srow, as is already done for the copied lines and extmark rows. --- runtime/lua/vim/_core/ui2/messages.lua | 3 +- test/functional/ui/messages2_spec.lua | 40 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/runtime/lua/vim/_core/ui2/messages.lua b/runtime/lua/vim/_core/ui2/messages.lua index 9178b7857f..2421647a81 100644 --- a/runtime/lua/vim/_core/ui2/messages.lua +++ b/runtime/lua/vim/_core/ui2/messages.lua @@ -239,7 +239,8 @@ function M.expand_msg(src, tgt, focus) api.nvim_buf_set_lines(ui.bufs[tgt], srow, -1, false, lines) for _, m in ipairs(marks) do - hlopts.hl_group, hlopts.end_col, hlopts.end_row = m[4].hl_group, m[4].end_col, m[4].end_row + hlopts.hl_group, hlopts.end_col, hlopts.end_row = + m[4].hl_group, m[4].end_col, srow + m[4].end_row api.nvim_buf_set_extmark(ui.bufs[tgt], ui.ns, srow + m[2], m[3], hlopts) end else diff --git a/test/functional/ui/messages2_spec.lua b/test/functional/ui/messages2_spec.lua index bb867306b9..306cdc324e 100644 --- a/test/functional/ui/messages2_spec.lua +++ b/test/functional/ui/messages2_spec.lua @@ -1346,4 +1346,44 @@ describe('messages2', function() end) screen:expect_unchanged() end) + + it('correct end_row for highlights copied to pager #41419', function() + command('echo "a" | echo "b"') -- Two lines; end_row should be offset by 2 + screen:expect([[ + ^ | + {1:~ }|*10 + {3: }| + a | + b | + ]]) + feed('g') + screen:expect([[ + | + {1:~ }|*9 + {3: }| + ^a | + b | + | + ]]) + command('echohl WarningMsg | echo "c" | echohl ErrorMsg | echo "de"') + screen:expect([[ + | + {1:~ }|*7 + {3: }| + ^a | + b | + {19:c} | + {9:de} | + | + ]]) + feed('g') + screen:expect([[ + | + {1:~ }|*9 + {3: }| + {19:^c} | + {9:de} | + | + ]]) + end) end)