Skip to content

Commit ce60687

Browse files
committed
fix: problem with get_surrounding_delim
refer: #3207
1 parent dc90fea commit ce60687

File tree

2 files changed

+75
-16
lines changed

2 files changed

+75
-16
lines changed

autoload/vimtex/delim.vim

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -491,37 +491,36 @@ function! s:get_surrounding_delim(type) abort " {{{1
491491
let l:save_pos = vimtex#pos#get_cursor()
492492
let l:pos_val_cursor = vimtex#pos#val(l:save_pos)
493493
let l:pos_val_last = l:pos_val_cursor
494-
let l:pos_val_open = l:pos_val_cursor - 1
494+
let l:pos_val_current = l:pos_val_cursor - 1
495495

496496
let l:count = 0
497-
while l:pos_val_open < l:pos_val_last && l:count < 100
497+
while l:pos_val_current < l:pos_val_last && l:count < 100
498498
let l:count += 1
499499
let l:open = vimtex#delim#get_prev(a:type, 'open')
500500
if empty(l:open) | break | endif
501501

502502
let l:env_close = vimtex#delim#get_next_after(l:open, 'env_all', 'close')
503+
let l:env_open = vimtex#delim#get_matching(l:env_close)
504+
505+
let l:pos_val_open = vimtex#pos#val(l:open)
506+
let l:pos_val_env_open = empty(l:env_open) ? 0 : vimtex#pos#val(l:env_open)
503507
let l:pos_val_env_close = empty(l:env_close)
504508
\ ? l:pos_val_cursor + 1
505509
\ : vimtex#pos#val(l:env_close) + strlen(l:env_close.match) - 1
506-
if l:pos_val_env_close > l:pos_val_cursor
507-
let l:close = vimtex#delim#get_matching(l:open)
508510

509-
let l:env_open = vimtex#delim#get_prev_before(l:close, 'env_all', 'open')
510-
let l:pos_val_env_open = empty(l:env_open)
511-
\ ? 0
512-
\ : vimtex#pos#val(l:env_open)
513-
if l:pos_val_env_open < l:pos_val_cursor
514-
let l:pos_val_try = vimtex#pos#val(l:close) + strlen(l:close.match) - 1
515-
if l:pos_val_try >= l:pos_val_cursor
516-
call vimtex#pos#set_cursor(l:save_pos)
517-
return [l:open, l:close]
518-
endif
511+
if l:pos_val_env_open > l:pos_val_open
512+
\ || l:pos_val_env_close > l:pos_val_cursor
513+
let l:close = vimtex#delim#get_matching(l:open)
514+
let l:pos_val_try = vimtex#pos#val(l:close) + strlen(l:close.match) - 1
515+
if l:pos_val_try >= l:pos_val_cursor
516+
call vimtex#pos#set_cursor(l:save_pos)
517+
return [l:open, l:close]
519518
endif
520519
endif
521520

522521
call vimtex#pos#set_cursor(vimtex#pos#prev(l:open))
523-
let l:pos_val_last = l:pos_val_open
524-
let l:pos_val_open = vimtex#pos#val(l:open)
522+
let l:pos_val_last = l:pos_val_current
523+
let l:pos_val_current = l:pos_val_open
525524
endwhile
526525

527526
call vimtex#pos#set_cursor(l:save_pos)

test/test-textobj/test-delims.vim

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
set nocompatible
2+
let &rtp = '../..,' . &rtp
3+
filetype plugin on
4+
syntax on
5+
6+
set nomore
7+
8+
setfiletype tex
9+
10+
call vimtex#test#keys('Edid',
11+
\ '\caption{Testing easy.}',
12+
\ '\caption{}'
13+
\)
14+
15+
call vimtex#test#keys('Edad',
16+
\ '\caption{Testing easy.}',
17+
\ '\caption'
18+
\)
19+
20+
call vimtex#test#keys('Edid',
21+
\ '\caption{Testing {nested}.}',
22+
\ '\caption{}'
23+
\)
24+
25+
call vimtex#test#keys('$bdid',
26+
\ '\caption{Testing {nested} after}',
27+
\ '\caption{}'
28+
\)
29+
30+
call vimtex#test#keys('Edid',
31+
\ '\caption{Testing $math$.}',
32+
\ '\caption{}'
33+
\)
34+
35+
call vimtex#test#keys('4jdid', [
36+
\ 'An interval like',
37+
\ '\begin{equation}',
38+
\ ' I = (0, 1]',
39+
\ '\end{equation}',
40+
\ 'is called half-open, just like the interval',
41+
\ '\[',
42+
\ ' J = [0, 1)',
43+
\ '\]',
44+
\], [
45+
\ 'An interval like',
46+
\ '\begin{equation}',
47+
\ ' I = (0, 1]',
48+
\ '\end{equation}',
49+
\ 'is called half-open, just like the interval',
50+
\ '\[',
51+
\ ' J = [0, 1)',
52+
\ '\]',
53+
\])
54+
55+
call vimtex#test#keys('$bdid',
56+
\ '\caption{Testing $math$ after}',
57+
\ '\caption{}'
58+
\)
59+
60+
call vimtex#test#finished()

0 commit comments

Comments
 (0)