ghost text inline (#1588)

This commit is contained in:
Anshuman Medhi
2023-05-25 23:02:26 +08:00
committed by GitHub
parent 799392ac8d
commit 950d0e3a93

View File

@@ -9,6 +9,8 @@ local ghost_text_view = {}
ghost_text_view.ns = vim.api.nvim_create_namespace('cmp:GHOST_TEXT')
local has_inline = vim.fn.has('nvim-0.10') == 1
ghost_text_view.new = function()
local self = setmetatable({}, { __index = ghost_text_view })
self.win = nil
@@ -17,7 +19,7 @@ ghost_text_view.new = function()
on_win = function(_, win)
return win == self.win
end,
on_line = function(_)
on_line = function(_, _, _, on_row)
local c = config.get().experimental.ghost_text
if not c then
return
@@ -28,17 +30,23 @@ ghost_text_view.new = function()
end
local row, col = unpack(vim.api.nvim_win_get_cursor(0))
local line = vim.api.nvim_get_current_line()
if string.sub(line, col + 1) ~= '' then
if on_row ~= row - 1 then
return
end
local line = vim.api.nvim_get_current_line()
if not has_inline then
if string.sub(line, col + 1) ~= '' then
return
end
end
local text = self.text_gen(self, line, col)
if #text > 0 then
vim.api.nvim_buf_set_extmark(0, ghost_text_view.ns, row - 1, col, {
right_gravity = false,
virt_text = { { text, type(c) == 'table' and c.hl_group or 'Comment' } },
virt_text_pos = 'overlay',
virt_text_pos = has_inline and 'inline' or 'overlay',
hl_mode = 'combine',
ephemeral = true,
})