Minuet autocomplete key again
This commit is contained in:
1 parent
429386b92e
commit
2fea845141
1 file changed
+27
-13
+27
-13
@@ -191,12 +191,12 @@ minuet.setup({
|
||||
auto_trigger_ft = { "*" },
|
||||
auto_trigger_ignore_ft = { "TelescopePrompt", "oil" },
|
||||
keymap = {
|
||||
-- Tab, mapped below.
|
||||
-- Accept and dismiss are <C-l> and <C-h>, mapped below.
|
||||
accept = false,
|
||||
accept_line = "<A-l>",
|
||||
accept_line = false,
|
||||
prev = "<A-[>",
|
||||
next = "<A-]>",
|
||||
dismiss = "<A-e>",
|
||||
dismiss = false,
|
||||
},
|
||||
},
|
||||
provider_options = {
|
||||
@@ -238,20 +238,34 @@ minuet.setup({
|
||||
},
|
||||
})
|
||||
|
||||
-- Tab accepts the whole suggestion. With none showing it falls back to the
|
||||
-- built-in snippet jump, then a plain Tab. <C-v><Tab> inserts a literal tab,
|
||||
-- since <C-v> bypasses mappings.
|
||||
-- <C-l> accepts one line; a second <C-l> within 300 ms accepts the rest, so a
|
||||
-- double tap takes the whole suggestion. <C-h> dismisses. With no suggestion
|
||||
-- showing, <C-h> deletes a character as usual and <C-l> does nothing (its
|
||||
-- default inserts a literal ^L).
|
||||
local minuet_vt = require("minuet.virtualtext").action
|
||||
vim.keymap.set("i", "<Tab>", function()
|
||||
if minuet_vt.is_visible() then
|
||||
vim.schedule(minuet_vt.accept)
|
||||
local minuet_last_accept = 0
|
||||
vim.keymap.set("i", "<C-l>", function()
|
||||
if not minuet_vt.is_visible() then
|
||||
return ""
|
||||
end
|
||||
if vim.snippet.active({ direction = 1 }) then
|
||||
return "<Cmd>lua vim.snippet.jump(1)<CR>"
|
||||
-- hrtime, not uv.now(): now() is cached per loop iteration and can miss
|
||||
-- the gap between two key presses.
|
||||
local now = vim.uv.hrtime() / 1e6
|
||||
local n_lines = 1
|
||||
if now - minuet_last_accept < 300 then
|
||||
n_lines = nil
|
||||
end
|
||||
return "<Tab>"
|
||||
end, { expr = true, silent = true, desc = "Accept minuet suggestion, else Tab" })
|
||||
minuet_last_accept = now
|
||||
vim.schedule(function() minuet_vt.accept(n_lines) end)
|
||||
return ""
|
||||
end, { expr = true, silent = true, desc = "Accept minuet line; double tap accepts all" })
|
||||
vim.keymap.set("i", "<C-h>", function()
|
||||
if minuet_vt.is_visible() then
|
||||
vim.schedule(minuet_vt.dismiss)
|
||||
return ""
|
||||
end
|
||||
return "<C-h>"
|
||||
end, { expr = true, silent = true, desc = "Dismiss minuet suggestion, else delete" })
|
||||
end
|
||||
|
||||
-- Ghost text, dimmer than a comment.
|
||||
|
||||
Reference in new issue
Block a user