Skip to content

Commit b9a2e4c

Browse files
committed
config: set_jumps option for select_textobject
fixes #842
1 parent f7122ac commit b9a2e4c

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ require("nvim-treesitter-textobjects").setup {
6868
-- * selection_mode: eg 'v'
6969
-- and should return true of false
7070
include_surrounding_whitespace = false,
71+
-- whether to set jumps in the jumplist
72+
set_jumps = false,
7173
},
7274
}
7375

lua/nvim-treesitter-textobjects/config.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
---@field lookbehind? boolean
88
---@field selection_modes? table<string, TSTextObjects.SelectionMode>|fun(opts: TSTextObjects.ConfigFunctionArgs): TSTextObjects.SelectionMode|table<string, TSTextObjects.SelectionMode>
99
---@field include_surrounding_whitespace? boolean|fun(opts: TSTextObjects.ConfigFunctionArgs): boolean
10+
---@field set_jumps? boolean
1011

1112
---@class (exact) TSTextObjects.Config.Move
1213
---@field set_jumps? boolean
@@ -29,6 +30,7 @@ local default_config = {
2930
lookbehind = false,
3031
selection_modes = {},
3132
include_surrounding_whitespace = false,
33+
set_jumps = false,
3234
},
3335
move = {
3436
set_jumps = true,

lua/nvim-treesitter-textobjects/select.lua

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local shared = require('nvim-treesitter-textobjects.shared')
44

55
---@param range Range4
66
---@param selection_mode TSTextObjects.SelectionMode
7-
local function update_selection(range, selection_mode)
7+
local function update_selection(range, selection_mode, set_jumps)
88
---@type integer, integer, integer, integer
99
local start_row, start_col, end_row, end_col = unpack(range)
1010
selection_mode = selection_mode or 'v'
@@ -33,6 +33,10 @@ local function update_selection(range, selection_mode)
3333
end
3434
end_col = end_col - end_col_offset
3535

36+
if set_jumps then
37+
vim.cmd("normal! m'")
38+
end
39+
3640
-- Position is 1, 0 indexed.
3741
api.nvim_win_set_cursor(0, { start_row + 1, start_col })
3842
vim.cmd('normal! o')
@@ -158,6 +162,7 @@ function M.select_textobject(query_string, query_group)
158162
local lookahead = config.lookahead
159163
local lookbehind = config.lookbehind
160164
local surrounding_whitespace = config.include_surrounding_whitespace
165+
local set_jumps = config.set_jumps
161166
local range6 = shared.textobject_at_point(
162167
query_string,
163168
query_group,
@@ -178,7 +183,7 @@ function M.select_textobject(query_string, query_group)
178183
range4 = include_surrounding_whitespace(bufnr, range4, selection_mode)
179184
end
180185
if range4 then
181-
update_selection(range4, selection_mode)
186+
update_selection(range4, selection_mode, set_jumps)
182187
end
183188
end
184189
end

0 commit comments

Comments
 (0)