fix(ghost_text): ephemeral-like inline ghost-text workaround (#1688)
Refs: - https://github.com/hrsh7th/nvim-cmp/pull/1645 - https://github.com/neovim/neovim/issues/24797
This commit is contained in:
@@ -24,11 +24,17 @@ ghost_text_view.new = function()
|
|||||||
local self = setmetatable({}, { __index = ghost_text_view })
|
local self = setmetatable({}, { __index = ghost_text_view })
|
||||||
self.win = nil
|
self.win = nil
|
||||||
self.entry = nil
|
self.entry = nil
|
||||||
|
self.extmark_id = nil
|
||||||
vim.api.nvim_set_decoration_provider(ghost_text_view.ns, {
|
vim.api.nvim_set_decoration_provider(ghost_text_view.ns, {
|
||||||
on_win = function(_, win)
|
on_win = function(_, win)
|
||||||
return win == self.win
|
if self.extmark_id then
|
||||||
end,
|
vim.api.nvim_buf_del_extmark(0, ghost_text_view.ns, self.extmark_id)
|
||||||
on_line = function(_, _, _, on_row)
|
end
|
||||||
|
|
||||||
|
if win ~= self.win then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
local c = config.get().experimental.ghost_text
|
local c = config.get().experimental.ghost_text
|
||||||
if not c then
|
if not c then
|
||||||
return
|
return
|
||||||
@@ -39,9 +45,6 @@ ghost_text_view.new = function()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
|
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||||
if on_row ~= row - 1 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local line = vim.api.nvim_get_current_line()
|
local line = vim.api.nvim_get_current_line()
|
||||||
if not has_inline then
|
if not has_inline then
|
||||||
@@ -52,12 +55,12 @@ ghost_text_view.new = function()
|
|||||||
|
|
||||||
local text = self.text_gen(self, line, col)
|
local text = self.text_gen(self, line, col)
|
||||||
if #text > 0 then
|
if #text > 0 then
|
||||||
vim.api.nvim_buf_set_extmark(0, ghost_text_view.ns, row - 1, col, {
|
self.extmark_id = vim.api.nvim_buf_set_extmark(0, ghost_text_view.ns, row - 1, col, {
|
||||||
right_gravity = false,
|
right_gravity = true,
|
||||||
virt_text = { { text, type(c) == 'table' and c.hl_group or 'Comment' } },
|
virt_text = { { text, type(c) == 'table' and c.hl_group or 'Comment' } },
|
||||||
virt_text_pos = has_inline and 'inline' or 'overlay',
|
virt_text_pos = has_inline and 'inline' or 'overlay',
|
||||||
hl_mode = 'combine',
|
hl_mode = 'combine',
|
||||||
ephemeral = true,
|
ephemeral = false,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|||||||
Reference in New Issue
Block a user