mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-13 00:40:06 -04:00
refactor(inc-selection): simplify keymap and add error message
This commit is contained in:
parent
1cda98132a
commit
140a486abe
1 changed files with 7 additions and 14 deletions
|
|
@ -5,6 +5,7 @@ local ts_utils = require "nvim-treesitter.ts_utils"
|
||||||
local locals = require "nvim-treesitter.locals"
|
local locals = require "nvim-treesitter.locals"
|
||||||
local parsers = require "nvim-treesitter.parsers"
|
local parsers = require "nvim-treesitter.parsers"
|
||||||
local queries = require "nvim-treesitter.query"
|
local queries = require "nvim-treesitter.query"
|
||||||
|
local utils = require "nvim-treesitter.utils"
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
|
@ -138,22 +139,14 @@ function M.attach(bufnr)
|
||||||
local config = configs.get_module "incremental_selection"
|
local config = configs.get_module "incremental_selection"
|
||||||
for funcname, mapping in pairs(config.keymaps) do
|
for funcname, mapping in pairs(config.keymaps) do
|
||||||
if mapping then
|
if mapping then
|
||||||
---@type string, string|function
|
local mode = funcname == "init_selection" and "n" or "x"
|
||||||
local mode, rhs
|
local rhs = M[funcname] ---@type function
|
||||||
if funcname == "init_selection" then
|
|
||||||
mode = "n"
|
if not rhs then
|
||||||
---@type function
|
utils.notify("Unknown keybinding: " .. funcname .. debug.traceback(), vim.log.levels.ERROR)
|
||||||
rhs = M[funcname]
|
|
||||||
else
|
else
|
||||||
mode = "x"
|
vim.keymap.set(mode, mapping, rhs, { buffer = bufnr, silent = true, desc = FUNCTION_DESCRIPTIONS[funcname] })
|
||||||
rhs = M[funcname] ---@type function
|
|
||||||
end
|
end
|
||||||
vim.keymap.set(
|
|
||||||
mode,
|
|
||||||
mapping,
|
|
||||||
rhs,
|
|
||||||
{ buffer = bufnr, silent = true, noremap = true, desc = FUNCTION_DESCRIPTIONS[funcname] }
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue