From 1351d62142959778d356bcfc5cad42d3ef7dcd09 Mon Sep 17 00:00:00 2001 From: CHENG-TING CHEN Date: Sat, 30 Aug 2025 01:24:47 +0800 Subject: [PATCH] fix: Correct header highlighting for multi-byte characters --- lua/CopilotChat/ui/chat.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lua/CopilotChat/ui/chat.lua b/lua/CopilotChat/ui/chat.lua index d6c1e283..315134e5 100644 --- a/lua/CopilotChat/ui/chat.lua +++ b/lua/CopilotChat/ui/chat.lua @@ -620,21 +620,21 @@ function Chat:render() if id then -- Draw the separator as virtual text over the header line, hiding the id and anything after the header if self.config.highlight_headers then - local sep_col = vim.fn.strwidth(header_value) - vim.api.nvim_buf_set_extmark(self.bufnr, highlight_ns, l - 1, sep_col, { + local header_width = vim.fn.strwidth(header_value) + vim.api.nvim_buf_set_extmark(self.bufnr, highlight_ns, l - 1, 0, { + end_col = #header_value, + hl_group = 'CopilotChatHeader', + priority = 100, + strict = false, + }) + vim.api.nvim_buf_set_extmark(self.bufnr, highlight_ns, l - 1, #header_value, { virt_text = { { string.rep(self.separator, vim.go.columns), 'CopilotChatSeparator' }, }, - virt_text_win_col = sep_col, + virt_text_win_col = header_width, priority = 200, strict = false, }) - vim.api.nvim_buf_set_extmark(self.bufnr, highlight_ns, l - 1, 0, { - end_col = sep_col, - hl_group = 'CopilotChatHeader', - priority = 100, - strict = false, - }) end -- Finish previous message