From b8ba2ec072f2de498eb07e7de78cc02d148ed862 Mon Sep 17 00:00:00 2001 From: Myzel394 <50424412+Myzel394@users.noreply.github.com> Date: Sat, 27 Apr 2024 00:20:03 +0200 Subject: [PATCH] feat: Add option for custom mappings --- lua/telescope/_extensions/jsonfly.lua | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/lua/telescope/_extensions/jsonfly.lua b/lua/telescope/_extensions/jsonfly.lua index 3c93d3d..ed59e01 100644 --- a/lua/telescope/_extensions/jsonfly.lua +++ b/lua/telescope/_extensions/jsonfly.lua @@ -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] ; Example: {"n", "a"} -> When in normal mode, press "a" to add the key; Example: {"i", ""} -> When in insert mode, press to add the key; Default: {"i", ""} --- ---@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", ""} + } } ---@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", "", 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,