Skip to content

Commit

Permalink
fix(ghost_text): always get buffer from window
Browse files Browse the repository at this point in the history
  • Loading branch information
max397574 committed Oct 19, 2024
1 parent d06972a commit af83001
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions lua/care/ghost_text.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ function Ghost_text.new()
end,
on_line = function()
if self.extmark_id then
vim.api.nvim_buf_del_extmark(vim.api.nvim_get_current_buf(), self.ns, self.extmark_id)
vim.api.nvim_buf_del_extmark(vim.api.nvim_win_get_buf(self.win), self.ns, self.extmark_id)
self.extmark_id = nil
end
if (not self.config.enabled) or not self.entry then
Expand All @@ -40,18 +40,28 @@ function Ghost_text.new()
local cursor = vim.api.nvim_win_get_cursor(self.win)
local text_after_filter = word:sub(cursor[2] - offset + 1)
if self.config.position == "inline" then
self.extmark_id =
vim.api.nvim_buf_set_extmark(vim.api.nvim_get_current_buf(), self.ns, cursor[1] - 1, cursor[2], {
self.extmark_id = vim.api.nvim_buf_set_extmark(
vim.api.nvim_win_get_buf(self.win),
self.ns,
cursor[1] - 1,
cursor[2],
{
virt_text = { { text_after_filter, "@care.ghost_text" } },
virt_text_pos = "inline",
})
}
)
elseif self.config.position == "overlay" then
self.extmark_id =
vim.api.nvim_buf_set_extmark(vim.api.nvim_get_current_buf(), self.ns, cursor[1] - 1, cursor[2], {
self.extmark_id = vim.api.nvim_buf_set_extmark(
vim.api.nvim_win_get_buf(self.win),
self.ns,
cursor[1] - 1,
cursor[2],
{
virt_text = { { text_after_filter, "@care.ghost_text" } },
virt_text_pos = "overlay",
ephemeral = true,
})
}
)
end
end,
})
Expand Down

0 comments on commit af83001

Please sign in to comment.