Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ require("nvim-treesitter-textobjects").setup {
-- * selection_mode: eg 'v'
-- and should return true of false
include_surrounding_whitespace = false,
-- whether to set jumps in the jumplist
set_jumps = false,
},
}

Expand Down
2 changes: 2 additions & 0 deletions lua/nvim-treesitter-textobjects/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
---@field lookbehind? boolean
---@field selection_modes? table<string, TSTextObjects.SelectionMode>|fun(opts: TSTextObjects.ConfigFunctionArgs): TSTextObjects.SelectionMode|table<string, TSTextObjects.SelectionMode>
---@field include_surrounding_whitespace? boolean|fun(opts: TSTextObjects.ConfigFunctionArgs): boolean
---@field set_jumps? boolean

---@class (exact) TSTextObjects.Config.Move
---@field set_jumps? boolean
Expand All @@ -29,6 +30,7 @@ local default_config = {
lookbehind = false,
selection_modes = {},
include_surrounding_whitespace = false,
set_jumps = false,
},
move = {
set_jumps = true,
Expand Down
9 changes: 7 additions & 2 deletions lua/nvim-treesitter-textobjects/select.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local shared = require('nvim-treesitter-textobjects.shared')

---@param range Range4
---@param selection_mode TSTextObjects.SelectionMode
local function update_selection(range, selection_mode)
local function update_selection(range, selection_mode, set_jumps)
---@type integer, integer, integer, integer
local start_row, start_col, end_row, end_col = unpack(range)
selection_mode = selection_mode or 'v'
Expand Down Expand Up @@ -33,6 +33,10 @@ local function update_selection(range, selection_mode)
end
end_col = end_col - end_col_offset

if set_jumps then
vim.cmd("normal! m'")
end

-- Position is 1, 0 indexed.
api.nvim_win_set_cursor(0, { start_row + 1, start_col })
vim.cmd('normal! o')
Expand Down Expand Up @@ -158,6 +162,7 @@ function M.select_textobject(query_string, query_group)
local lookahead = config.lookahead
local lookbehind = config.lookbehind
local surrounding_whitespace = config.include_surrounding_whitespace
local set_jumps = config.set_jumps
local range6 = shared.textobject_at_point(
query_string,
query_group,
Expand All @@ -178,7 +183,7 @@ function M.select_textobject(query_string, query_group)
range4 = include_surrounding_whitespace(bufnr, range4, selection_mode)
end
if range4 then
update_selection(range4, selection_mode)
update_selection(range4, selection_mode, set_jumps)
end
end
end
Expand Down
Loading