mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-02 03:26:52 -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 parsers = require "nvim-treesitter.parsers"
|
||||
local queries = require "nvim-treesitter.query"
|
||||
local utils = require "nvim-treesitter.utils"
|
||||
|
||||
local M = {}
|
||||
|
||||
|
|
@ -138,22 +139,14 @@ function M.attach(bufnr)
|
|||
local config = configs.get_module "incremental_selection"
|
||||
for funcname, mapping in pairs(config.keymaps) do
|
||||
if mapping then
|
||||
---@type string, string|function
|
||||
local mode, rhs
|
||||
if funcname == "init_selection" then
|
||||
mode = "n"
|
||||
---@type function
|
||||
rhs = M[funcname]
|
||||
local mode = funcname == "init_selection" and "n" or "x"
|
||||
local rhs = M[funcname] ---@type function
|
||||
|
||||
if not rhs then
|
||||
utils.notify("Unknown keybinding: " .. funcname .. debug.traceback(), vim.log.levels.ERROR)
|
||||
else
|
||||
mode = "x"
|
||||
rhs = M[funcname] ---@type function
|
||||
vim.keymap.set(mode, mapping, rhs, { buffer = bufnr, silent = true, desc = FUNCTION_DESCRIPTIONS[funcname] })
|
||||
end
|
||||
vim.keymap.set(
|
||||
mode,
|
||||
mapping,
|
||||
rhs,
|
||||
{ buffer = bufnr, silent = true, noremap = true, desc = FUNCTION_DESCRIPTIONS[funcname] }
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue