mirror of
https://github.com/folke/snacks.nvim
synced 2025-12-23 08:47:57 +00:00
fix(scope): allow user to disable keys (#1918)
## Description Currently the user is not able to disable the existing keys in `keys.textobject`, because if he sets for example `ii = false`, it throws an error about not being able to index `opts`. <!-- Describe the big picture of your changes to communicate to the maintainers why we should accept this pull request. --> ## Related Issue(s) None, rather a LazyVim discussion https://github.com/LazyVim/LazyVim/discussions/6118 <!-- If this PR fixes any issues, please link to the issue here. - Fixes #<issue_number> --> ## Screenshots <!-- Add screenshots of the changes if applicable. --> --------- Co-authored-by: Folke Lemaitre <folke.lemaitre@gmail.com>
This commit is contained in:
parent
425c1e8e85
commit
bebf0bd38e
1 changed files with 12 additions and 8 deletions
|
|
@ -68,7 +68,7 @@ local defaults = {
|
|||
-- Alternatively, you can set them manually in your config,
|
||||
-- using the `Snacks.scope.textobject` and `Snacks.scope.jump` functions.
|
||||
keys = {
|
||||
---@type table<string, snacks.scope.TextObject|{desc?:string}>
|
||||
---@type table<string, snacks.scope.TextObject|{desc?:string}|false>
|
||||
textobject = {
|
||||
ii = {
|
||||
min_size = 2, -- minimum size of the scope
|
||||
|
|
@ -84,7 +84,7 @@ local defaults = {
|
|||
desc = "full scope",
|
||||
},
|
||||
},
|
||||
---@type table<string, snacks.scope.Jump|{desc?:string}>
|
||||
---@type table<string, snacks.scope.Jump|{desc?:string}|false>
|
||||
jump = {
|
||||
["[i"] = {
|
||||
min_size = 1, -- allow single line scopes
|
||||
|
|
@ -774,14 +774,18 @@ end
|
|||
function M.setup()
|
||||
local keys = Snacks.config.get("scope", defaults).keys
|
||||
for key, opts in pairs(keys.textobject) do
|
||||
vim.keymap.set({ "x", "o" }, key, function()
|
||||
M.textobject(opts)
|
||||
end, { silent = true, desc = opts.desc })
|
||||
if opts then
|
||||
vim.keymap.set({ "x", "o" }, key, function()
|
||||
M.textobject(opts)
|
||||
end, { silent = true, desc = opts.desc })
|
||||
end
|
||||
end
|
||||
for key, opts in pairs(keys.jump) do
|
||||
vim.keymap.set({ "n", "x", "o" }, key, function()
|
||||
M.jump(opts)
|
||||
end, { silent = true, desc = opts.desc })
|
||||
if opts then
|
||||
vim.keymap.set({ "n", "x", "o" }, key, function()
|
||||
M.jump(opts)
|
||||
end, { silent = true, desc = opts.desc })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue