Skip to content

Commit

Permalink
fix: silly regression bug
Browse files Browse the repository at this point in the history
refer: #2313, #2370
  • Loading branch information
lervag committed Apr 9, 2022
1 parent cc70bde commit 5811c8e
Showing 1 changed file with 54 additions and 53 deletions.
107 changes: 54 additions & 53 deletions autoload/vimtex/delim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -125,59 +125,6 @@ function! vimtex#delim#toggle_modifier(...) abort " {{{1
return newmods
endfunction

" }}}1
function! vimtex#delim#toggle_modifier_all() abort " {{{1
" Save cursor position
let l:cursor = vimtex#pos#get_cursor()

" Use syntax highlights to detect region math region
let l:ww = &whichwrap
set whichwrap=h
while vimtex#syntax#in_mathzone()
normal! h
if vimtex#pos#get_cursor()[1:2] == [1, 1] | break | endif
endwhile
let &whichwrap = l:ww
let l:startval = vimtex#pos#val(vimtex#pos#get_cursor())

let l:undostore = v:true
call vimtex#pos#set_cursor(l:cursor)

while v:true
let [l:open, l:close] = vimtex#delim#get_surrounding('delim_modq_math')
if empty(l:open) || vimtex#pos#val(l:open) <= l:startval
break
endif

call vimtex#pos#set_cursor(vimtex#pos#prev(l:open))
if !empty(l:open.mod) | continue | endif

if l:undostore
let l:undostore = v:false
call vimtex#pos#set_cursor(l:cursor)
call vimtex#util#undostore()
call vimtex#pos#set_cursor(vimtex#pos#prev(l:open))
endif

" Add close modifier
let line = getline(l:close.lnum)
let line = strpart(line, 0, l:close.cnum - 1)
\ . '\right' . strpart(line, l:close.cnum - 1)
call setline(l:close.lnum, line)

" Add open modifier
let line = getline(l:open.lnum)
let line = strpart(line, 0, l:open.cnum - 1)
\ . '\left' . strpart(line, l:open.cnum - 1)
call setline(l:open.lnum, line)

" Adjust cursor position
let l:cursor[2] += 5
endwhile

call vimtex#pos#set_cursor(l:cursor)
endfunction

" }}}1
function! vimtex#delim#toggle_modifier_visual(...) abort " {{{1
let l:args = a:0 > 0 ? a:1 : {}
Expand Down Expand Up @@ -254,6 +201,60 @@ endfunction

" }}}1

function! vimtex#delim#add_modifiers() abort " {{{1
" Save cursor position
let l:cursor = vimtex#pos#get_cursor()

" Use syntax highlights to detect region math region
let l:ww = &whichwrap
set whichwrap=h
while vimtex#syntax#in_mathzone()
normal! h
if vimtex#pos#get_cursor()[1:2] == [1, 1] | break | endif
endwhile
let &whichwrap = l:ww
let l:startval = vimtex#pos#val(vimtex#pos#get_cursor())

let l:undostore = v:true
call vimtex#pos#set_cursor(l:cursor)

while v:true
let [l:open, l:close] = vimtex#delim#get_surrounding('delim_modq_math')
if empty(l:open) || vimtex#pos#val(l:open) <= l:startval
break
endif

call vimtex#pos#set_cursor(vimtex#pos#prev(l:open))
if !empty(l:open.mod) | continue | endif

if l:undostore
let l:undostore = v:false
call vimtex#pos#set_cursor(l:cursor)
call vimtex#util#undostore()
call vimtex#pos#set_cursor(vimtex#pos#prev(l:open))
endif

" Add close modifier
let line = getline(l:close.lnum)
let line = strpart(line, 0, l:close.cnum - 1)
\ . '\right' . strpart(line, l:close.cnum - 1)
call setline(l:close.lnum, line)

" Add open modifier
let line = getline(l:open.lnum)
let line = strpart(line, 0, l:open.cnum - 1)
\ . '\left' . strpart(line, l:open.cnum - 1)
call setline(l:open.lnum, line)

" Adjust cursor position
let l:cursor[2] += 5
endwhile

call vimtex#pos#set_cursor(l:cursor)
endfunction

" }}}1

function! vimtex#delim#change(...) abort " {{{1
let [l:open, l:close] = vimtex#delim#get_surrounding('delim_math')
if empty(l:open) | return | endif
Expand Down

0 comments on commit 5811c8e

Please sign in to comment.