@@ -94,10 +94,18 @@ local val_or_return = function(val, opts)
9494 end
9595end
9696
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 )
9898 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
101109 local surrounding_whitespace = configs .get_module (" textobjects.select" ).include_surrounding_whitespace
102110 local bufnr , textobject =
103111 shared .textobject_at_point (query_string , query_group , nil , nil , { lookahead = lookahead , lookbehind = lookbehind })
@@ -157,11 +165,13 @@ function M.attach(bufnr, lang)
157165 lang = lang or parsers .get_buf_lang (bufnr )
158166
159167 for mapping , query in pairs (config .keymaps ) do
160- local desc , query_string , query_group
168+ local desc , query_string , query_group , lookbehind , lookahead
161169 if type (query ) == " table" then
162170 desc = query .desc
163171 query_string = query .query
164172 query_group = query .query_group or " textobjects"
173+ lookbehind = query .lookbehind
174+ lookahead = query .lookahead
165175 else
166176 query_string = query
167177 query_group = " textobjects"
@@ -190,10 +200,12 @@ function M.attach(bufnr, lang)
190200 { keymap_mode },
191201 mapping ,
192202 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>" ,
194204 query_string ,
195205 query_group ,
196- keymap_mode
206+ keymap_mode ,
207+ lookahead ,
208+ lookbehind
197209 ),
198210 { buffer = bufnr , silent = true , remap = false , desc = desc }
199211 )
0 commit comments