mirror of
https://github.com/folke/snacks.nvim
synced 2025-07-07 13:15:08 +00:00
feat(picker.input): added some ctrl+r keymaps similar to cmdline. Closes #1420
This commit is contained in:
parent
4ce197bff9
commit
c864a7d378
2 changed files with 30 additions and 0 deletions
|
@ -13,6 +13,9 @@ local M = {}
|
|||
---@field field? string
|
||||
---@field notify? boolean
|
||||
|
||||
---@class snacks.picker.insert.Action: snacks.picker.Action
|
||||
---@field expr string
|
||||
|
||||
---@enum (key) snacks.picker.EditCmd
|
||||
local edit_cmd = {
|
||||
edit = "buffer",
|
||||
|
@ -197,6 +200,26 @@ function M.toggle_maximize(picker)
|
|||
picker.layout:maximize()
|
||||
end
|
||||
|
||||
function M.insert(picker, _, action)
|
||||
---@cast action snacks.picker.insert.Action
|
||||
if action.expr then
|
||||
local value = ""
|
||||
vim.api.nvim_buf_call(picker.input.filter.current_buf, function()
|
||||
value = action.expr == "line" and vim.api.nvim_get_current_line() or vim.fn.expand(action.expr)
|
||||
end)
|
||||
vim.api.nvim_win_call(picker.input.win.win, function()
|
||||
vim.api.nvim_put({ value }, "c", true, true)
|
||||
end)
|
||||
end
|
||||
end
|
||||
M.insert_cword = { action = "insert", expr = "<cword>" }
|
||||
M.insert_cWORD = { action = "insert", expr = "<cWORD>" }
|
||||
M.insert_filename = { action = "insert", expr = "%" }
|
||||
M.insert_file = { action = "insert", expr = "<cfile>" }
|
||||
M.insert_line = { action = "insert", expr = "line" }
|
||||
M.insert_file_full = { action = "insert", expr = "<cfile>:p" }
|
||||
M.insert_alt = { action = "insert", expr = "#" }
|
||||
|
||||
function M.toggle_preview(picker)
|
||||
picker:toggle("preview")
|
||||
end
|
||||
|
|
|
@ -233,6 +233,13 @@ local defaults = {
|
|||
["<c-t>"] = { "tab", mode = { "n", "i" } },
|
||||
["<c-u>"] = { "list_scroll_up", mode = { "i", "n" } },
|
||||
["<c-v>"] = { "edit_vsplit", mode = { "i", "n" } },
|
||||
["<c-r>#"] = { "insert_alt", mode = "i" },
|
||||
["<c-r>%"] = { "insert_filename", mode = "i" },
|
||||
["<c-r><c-a>"] = { "insert_cWORD", mode = "i" },
|
||||
["<c-r><c-f>"] = { "insert_file", mode = "i" },
|
||||
["<c-r><c-l>"] = { "insert_line", mode = "i" },
|
||||
["<c-r><c-p>"] = { "insert_file_full", mode = "i" },
|
||||
["<c-r><c-w>"] = { "insert_cword", mode = "i" },
|
||||
["<c-w>H"] = "layout_left",
|
||||
["<c-w>J"] = "layout_bottom",
|
||||
["<c-w>K"] = "layout_top",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue