Skip to content

Commit

Permalink
fix(virtual): remove extmark from correct buffer where it was set. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Oct 12, 2023
1 parent fcd0171 commit e5a4c7a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lua/noice/view/backend/virtualtext.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@ local View = require("noice.view")

---@class VirtualText: NoiceView
---@field extmark? number
---@field buf? number
---@diagnostic disable-next-line: undefined-field
local VirtualText = View:extend("VirtualTextView")

function VirtualText:show()
self:hide()
self.buf = vim.api.nvim_get_current_buf()

---@type number, number
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
line = line - 1

if self._messages[1] then
self.extmark = vim.api.nvim_buf_set_extmark(0, Config.ns, line, col, {
self.extmark = vim.api.nvim_buf_set_extmark(self.buf, Config.ns, line, col, {
virt_text_pos = "eol",
virt_text = { { vim.trim(self._messages[1]:content()), self._opts.hl_group or "DiagnosticVirtualTextInfo" } },
hl_mode = "combine",
Expand All @@ -26,7 +28,7 @@ end

function VirtualText:hide()
if self.extmark then
vim.api.nvim_buf_del_extmark(0, Config.ns, self.extmark)
vim.api.nvim_buf_del_extmark(self.buf, Config.ns, self.extmark)
end
end

Expand Down

0 comments on commit e5a4c7a

Please sign in to comment.