Skip to content

Commit 958539a

Browse files
committed
fix: only check for math environments
refer: #3219
1 parent a50f407 commit 958539a

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

autoload/vimtex/env.vim

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,28 @@ function! vimtex#env#get_surrounding_or_next(type) abort
8888
if !empty(l:open) | return [l:open, l:close] | endif
8989

9090
" Finally check for standard math environments
91-
let [l:open, l:close] = vimtex#delim#get_surrounding_or_next('env_tex')
92-
return [l:open, l:close]
91+
let l:save_pos = vimtex#pos#get_cursor()
92+
let l:pv_current = vimtex#pos#val(l:save_pos)
93+
let l:pv_prev = 0
94+
while v:true && l:pv_current != l:pv_prev
95+
let [l:open, l:close] = vimtex#delim#get_surrounding_or_next('env_tex')
96+
if empty(l:open)
97+
call vimtex#pos#set_cursor(l:save_pos)
98+
return [l:open, l:close]
99+
endif
100+
101+
if index(s:math_envs, substitute(l:open.name, '\*$', '', '')) >= 0
102+
call vimtex#pos#set_cursor(l:save_pos)
103+
return [l:open, l:close]
104+
endif
105+
106+
let l:pos_next = vimtex#pos#prev(l:open)
107+
let l:pv_prev = l:pv_current
108+
let l:pv_current = vimtex#pos#val(l:pos_next)
109+
call vimtex#pos#set_cursor(l:pos_next)
110+
endwhile
111+
112+
return [{}, {}]
93113
endfunction
94114

95115
let s:math_envs = [

test/test-textobj/test-other.vim

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,19 @@ call vimtex#test#keys('da$',
3131
\ 'Hello world! $(x)$',
3232
\ 'Hello world! ')
3333

34+
call vimtex#test#keys('jjda$',
35+
\ [
36+
\ '\documentclass{minimal}',
37+
\ '\begin{document}',
38+
\ 'Hello world!',
39+
\ '\end{document}',
40+
\ ],
41+
\ [
42+
\ '\documentclass{minimal}',
43+
\ '\begin{document}',
44+
\ 'Hello world!',
45+
\ '\end{document}',
46+
\ ],
47+
\)
48+
3449
call vimtex#test#finished()

0 commit comments

Comments
 (0)