Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(visual): Fix syncing vscode selection to nvim #1647

Merged
merged 1 commit into from
Nov 22, 2023

Conversation

xiyaowong
Copy link
Collaborator

Fixes #1645

@justinmk
Copy link
Collaborator

VisualChanged will land soonish: neovim/neovim#26052 , does that avoid any of this extra code?

@xiyaowong
Copy link
Collaborator Author

a little

function M.setup_visual_changed(group)
-- Simulate VisualChanged event
-- TODO: https://github.com/neovim/neovim/issues/19708
local visual_ns = api.nvim_create_namespace("vscode-neovim.visual.changed")
local is_visual, last_visual_pos, last_curr_pos
local function fire_visual_changed()
fn.VSCodeExtensionNotify("visual-changed", api.nvim_get_current_win())
end
api.nvim_create_autocmd({ "ModeChanged" }, {
group = group,
callback = function(ev)
local mode = api.nvim_get_mode().mode
-- save current mode
is_visual = mode:match("[vV\x16]")
-- handle mode changes
if ev.match:match("[vV\x16]") then
last_visual_pos = fn.getpos("v")
last_curr_pos = fn.getpos(".")
fire_visual_changed()
end
end,
})
api.nvim_set_decoration_provider(visual_ns, {
on_win = function()
if is_visual then
local visual_pos = fn.getpos("v")
local curr_pos = fn.getpos(".")
if not (vim.deep_equal(visual_pos, last_visual_pos) and vim.deep_equal(curr_pos, last_curr_pos)) then
last_visual_pos = visual_pos
last_curr_pos = curr_pos
fire_visual_changed()
end
end
end,
})
end

@xiyaowong
Copy link
Collaborator Author

this extra code?

Do you mean this pr? No

@YuruiHong
Copy link

YuruiHong commented Nov 22, 2023

Working for me, which is really helpful! Hopefully this will get merged soon.

@xiyaowong xiyaowong merged commit 8d2a14a into vscode-neovim:master Nov 22, 2023
8 checks passed
@xiyaowong xiyaowong deleted the visual/code-to-nvim branch November 22, 2023 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: Selecting CJK characters using mouse in normal mode is weird
3 participants