@@ -94,10 +94,18 @@ local val_or_return = function(val, opts)
94
94
end
95
95
end
96
96
97
- function M .select_textobject (query_string , query_group , keymap_mode )
97
+ function M .select_textobject (query_string , query_group , keymap_mode , local_lookahead , local_lookbehind )
98
98
query_group = query_group or " textobjects"
99
- local lookahead = configs .get_module (" textobjects.select" ).lookahead
100
- local lookbehind = configs .get_module (" textobjects.select" ).lookbehind
99
+ if local_lookahead == " nil" then
100
+ local_lookahead = nil
101
+ end
102
+ if local_lookbehind == " nil" then
103
+ local_lookbehind = nil
104
+ end
105
+ local global_lookahead = configs .get_module (" textobjects.select" ).lookahead
106
+ local global_lookbehind = configs .get_module (" textobjects.select" ).lookbehind
107
+ local lookahead = (global_lookahead and not local_lookbehind ) or local_lookahead
108
+ local lookbehind = (global_lookbehind and not local_lookahead ) or local_lookbehind
101
109
local surrounding_whitespace = configs .get_module (" textobjects.select" ).include_surrounding_whitespace
102
110
local bufnr , textobject =
103
111
shared .textobject_at_point (query_string , query_group , nil , nil , { lookahead = lookahead , lookbehind = lookbehind })
@@ -157,11 +165,13 @@ function M.attach(bufnr, lang)
157
165
lang = lang or parsers .get_buf_lang (bufnr )
158
166
159
167
for mapping , query in pairs (config .keymaps ) do
160
- local desc , query_string , query_group
168
+ local desc , query_string , query_group , lookbehind , lookahead
161
169
if type (query ) == " table" then
162
170
desc = query .desc
163
171
query_string = query .query
164
172
query_group = query .query_group or " textobjects"
173
+ lookbehind = query .lookbehind
174
+ lookahead = query .lookahead
165
175
else
166
176
query_string = query
167
177
query_group = " textobjects"
@@ -190,10 +200,12 @@ function M.attach(bufnr, lang)
190
200
{ keymap_mode },
191
201
mapping ,
192
202
string.format (
193
- " <cmd>lua require'nvim-treesitter.textobjects.select'.select_textobject('%s','%s','%s')<cr>" ,
203
+ " <cmd>lua require'nvim-treesitter.textobjects.select'.select_textobject('%s','%s','%s','%s','%s' )<cr>" ,
194
204
query_string ,
195
205
query_group ,
196
- keymap_mode
206
+ keymap_mode ,
207
+ lookahead ,
208
+ lookbehind
197
209
),
198
210
{ buffer = bufnr , silent = true , remap = false , desc = desc }
199
211
)
0 commit comments