mirror of
https://github.com/Myzel394/jsonfly.nvim.git
synced 2025-06-18 04:05:26 +02:00
feat: Add option for custom mappings
This commit is contained in:
parent
fbc1aa0424
commit
b8ba2ec072
@ -12,6 +12,10 @@
|
||||
---@field subkeys_display "normal"|"waterfall" - Display subkeys in a normal or waterfall style, Default: "normal"
|
||||
---@field backend "lua"|"lsp" - Backend to use for parsing JSON, "lua" = Use our own Lua parser to parse the JSON, "lsp" = Use your LSP to parse the JSON (currently only https://github.com/Microsoft/vscode-json-languageservice is supported). If the "lsp" backend is selected but the LSP fails, it will fallback to the "lua" backend, Default: "lsp"
|
||||
---@field use_cache number - Whether to use cache the parsed JSON. The cache will be activated if the number of lines is greater or equal to this value, By default, the cache is activate when the file if 1000 lines or more; `0` to disable the cache, Default: 500
|
||||
---@field commands Commands - Shortcuts for commands
|
||||
--
|
||||
---@class Commands
|
||||
---@field add_key string[] - Add the currently entered key to the JSON. Must be of type [string, string] <mode, key>; Example: {"n", "a"} -> When in normal mode, press "a" to add the key; Example: {"i", "<C-a>"} -> When in insert mode, press <C-a> to add the key; Default: {"i", "<C-a>"}
|
||||
---
|
||||
---@class Highlights
|
||||
---@field number string - Highlight group for numbers, Default: "@number.json"
|
||||
@ -53,6 +57,9 @@ local opts = {
|
||||
subkeys_display = "normal",
|
||||
backend = "lsp",
|
||||
use_cache = 500,
|
||||
commands = {
|
||||
add_key = {"i", "<C-a>"}
|
||||
}
|
||||
}
|
||||
|
||||
---@param entries Entry[]
|
||||
@ -80,14 +87,18 @@ local function show_picker(entries, buffer)
|
||||
pickers.new(opts, {
|
||||
prompt_title = opts.prompt_title,
|
||||
attach_mappings = function(_, map)
|
||||
map("i", "<C-a>", function(prompt_bufnr)
|
||||
local current_picker = action_state.get_current_picker(prompt_bufnr)
|
||||
local input = current_picker:_get_prompt()
|
||||
map(
|
||||
opts.commands.add_key[1],
|
||||
opts.commands.add_key[2],
|
||||
function(prompt_bufnr)
|
||||
local current_picker = action_state.get_current_picker(prompt_bufnr)
|
||||
local input = current_picker:_get_prompt()
|
||||
|
||||
local key_descriptor = utils:extract_key_description(input)
|
||||
local key_descriptor = utils:extract_key_description(input)
|
||||
|
||||
insert:insert_new_key(entries, key_descriptor, buffer)
|
||||
end)
|
||||
insert:insert_new_key(entries, key_descriptor, buffer)
|
||||
end
|
||||
)
|
||||
|
||||
return true
|
||||
end,
|
||||
|
Loading…
x
Reference in New Issue
Block a user