Disable inlay hints during the leap motion

This commit is contained in:
Martin Larsson 2024-04-17 11:01:32 +02:00
parent d1e2e4dea6
commit b9a4770fbe

View file

@ -1,3 +1,31 @@
local buffers_without_inlay_hints = {}
local function set_inlay_hints_active(buffers, enable)
for i, bufnr in pairs(buffers) do
vim.lsp.inlay_hint.enable(bufnr, enable)
end
end
local function get_open_buffers_with_inlay_hints()
local buffers = {}
for _, win in ipairs(vim.api.nvim_list_wins()) do
local bufnr = vim.api.nvim_win_get_buf(win)
if vim.lsp.inlay_hint.is_enabled(bufnr) then
table.insert(buffers, bufnr)
end
end
return buffers
end
local function add_leap_autocmd(pattern, callback)
vim.api.nvim_create_autocmd("User", {
pattern = pattern,
callback = function()
callback()
end,
})
end
return { return {
"ggandor/leap.nvim", "ggandor/leap.nvim",
dependencies = { dependencies = {
@ -7,27 +35,26 @@ return {
local leap = require("leap") local leap = require("leap")
leap.opts.safe_labels = {} leap.opts.safe_labels = {}
-- Hide the (real) cursor when leaping, and restore it afterwards. local autocmds = {
vim.api.nvim_create_autocmd(
"User",
{ {
pattern = "LeapEnter", pattern = "LeapEnter",
callback = function() cb = function()
vim.cmd.hi("Cursor", "blend=100") local open_buffers = get_open_buffers_with_inlay_hints()
vim.opt.guicursor:append { "a:Cursor/lCursor" } set_inlay_hints_active(open_buffers, false)
end, buffers_without_inlay_hints = open_buffers
} end
) },
vim.api.nvim_create_autocmd(
"User",
{ {
pattern = "LeapLeave", pattern = "LeapLeave",
callback = function() cb = function()
vim.cmd.hi("Cursor", "blend=0") set_inlay_hints_active(buffers_without_inlay_hints, true)
vim.opt.guicursor:remove { "a:Cursor/lCursor" } end
end, },
} }
)
for _, cmd in ipairs(autocmds) do
add_leap_autocmd(cmd.pattern, cmd.cb)
end
require("utils").add_keymaps({ require("utils").add_keymaps({
n = { n = {