nvim-treesitter-textobjects
nvim-treesitter-textobjects copied to clipboard
include_surrounding_whitespace should be an option on the mapping itself
Instead of requiring users to implement and write their own monolithic function themselves as in
keymaps = {
["af"] = "@function.outer",
["if"] = "@function.inner",
["aa"] = "@attribute.outer",
["ia"] = "@attribute.inner",
....
],
include_surrounding_whitespace = function (a)
if a.query_string == "@function.outer" then
return false
elseif a.query_string == "@function.inner" then
return false
elseif a.query_string == "@attribute.outer" then
return true
elseif a.query_string == "@attribute.inner" then
return false
....
end
I think making it an option on the keymap is a nicer and more expected API:
keymaps = {
["af"] = "@function.outer",
["if"] = "@function.inner",
["aa"] = { query = "@attribute.outer", includes_surrounding_whitespace = true },
["ia"] = "@attribute.inner",
....
],
I am also having a problem trying to make an include_surrounding_whitespace
function now,
include_surrounding_whitespace = function (a)
print(vim.inspect(a))
print(vim.inspect(a.query_name))
...
prints
{
query_string = "@attribute.outer",
selection_mode = "v"
}
nil
The query_name
field on the parameter is somehow nil
, even though the table looks pretty correct according to vim.inspect
@myarcana, I think you're looking for query_string, like in your original snippet, not for query_name? I have a variation of your snippet in my config, and it works:
include_surrounding_whitespace = function (query)
if string.find(query.query_string, "outer") then
return true
end
return false
end
+1 on handling it via an option