mirror of
https://github.com/LazyVim/LazyVim.git
synced 2025-07-15 11:54:36 +02:00
fix(treesitter-textobjects): use normal ]c,]C,[c,[C when in diff-mode instead of goto class. Fixes #1610
This commit is contained in:
parent
237be9e3a7
commit
1935486ff1
1 changed files with 18 additions and 8 deletions
|
@ -11,16 +11,26 @@ return {
|
||||||
{
|
{
|
||||||
"nvim-treesitter/nvim-treesitter-textobjects",
|
"nvim-treesitter/nvim-treesitter-textobjects",
|
||||||
config = function()
|
config = function()
|
||||||
-- Disable class keymaps in diff mode
|
-- When in diff mode, we want to use the default
|
||||||
vim.api.nvim_create_autocmd("BufReadPost", {
|
-- vim text objects c & C instead of the treesitter ones.
|
||||||
callback = function(event)
|
local move = require("nvim-treesitter.textobjects.move") ---@type table<string,fun(...)>
|
||||||
|
local configs = require("nvim-treesitter.configs")
|
||||||
|
for name, fn in pairs(move) do
|
||||||
|
if name:find("goto") == 1 then
|
||||||
|
move[name] = function(q, ...)
|
||||||
if vim.wo.diff then
|
if vim.wo.diff then
|
||||||
for _, key in ipairs({ "[c", "]c", "[C", "]C" }) do
|
local config = configs.get_module("textobjects.move")[name] ---@type table<string,string>
|
||||||
pcall(vim.keymap.del, "n", key, { buffer = event.buf })
|
for key, query in pairs(config or {}) do
|
||||||
|
if q == query and key:find("[%]%[][cC]") then
|
||||||
|
vim.cmd("normal! " .. key)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return fn(q, ...)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
|
||||||
})
|
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue