Skip to content

Commit

Permalink
fix(visual): clear fake cursor correctly (#1552)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiyaowong committed Oct 20, 2023
1 parent 35ec974 commit c786074
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions runtime/lua/vscode-neovim/cursor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -117,31 +117,31 @@ end

-- --------------------------- fake visual cursor --------------------------- --
-- in visual mode, decorate a fake cursor so that vscode can use the primary cursor for selection
M.fake_ns = vim.api.nvim_create_namespace("vscode-fake-visual-cursor")
M.fake_cursor = nil

function M.highlight_fake_cursor()
if M.fake_cursor then
vim.api.nvim_buf_del_extmark(0, M.fake_ns, M.fake_cursor)
local fake_cursor_ns = api.nvim_create_namespace("vscode-fake-visual-cursor")
local fake_cursor = nil
local function highlight_fake_cursor()
if fake_cursor then
fake_cursor = nil
for _, buf in ipairs(api.nvim_list_bufs()) do
api.nvim_buf_clear_namespace(buf, fake_cursor_ns, 0, -1)
end
end
if util.is_visual_mode() then
local line = vim.fn.line(".")
local col = vim.fn.col(".")
local ch = util.get_char_at(line, col) or " "
M.fake_cursor = vim.api.nvim_buf_set_extmark(
0,
M.fake_ns,
line - 1,
col - 1,
{ virt_text = { { ch, "Cursor" } }, virt_text_pos = "overlay", hl_mode = "replace", priority = 65534 }
)
fake_cursor = api.nvim_buf_set_extmark(0, fake_cursor_ns, line - 1, col - 1, {
virt_text = { { ch, "Cursor" } },
virt_text_pos = "overlay",
priority = 65534,
})
end
end

function M.setup_fake_cursor(group)
vim.api.nvim_create_autocmd({ "ModeChanged", "CursorMoved" }, {
api.nvim_create_autocmd({ "ModeChanged", "CursorMoved" }, {
group = group,
callback = M.highlight_fake_cursor,
callback = highlight_fake_cursor,
})
end

Expand Down

0 comments on commit c786074

Please sign in to comment.