mirror of
https://github.com/chenasraf/vim-matchup.git
synced 2026-05-18 01:38:57 +00:00
Fix pos#prev/next, improve motion for unicode
This commit is contained in:
@@ -216,8 +216,7 @@ function! matchup#motion#find_unmatched(visual, down) " {{{1
|
||||
if l:exclusive
|
||||
let l:new_pos[1] -= 1
|
||||
else
|
||||
"XXX spin this off
|
||||
let l:new_pos[1] += strdisplaywidth(l:delim.match) - 1
|
||||
let l:new_pos[1] += matchup#delim#end_offset(l:delim)
|
||||
endif
|
||||
endif
|
||||
|
||||
@@ -270,10 +269,7 @@ function! matchup#motion#jump_inside(visual) " {{{1
|
||||
endif
|
||||
|
||||
let l:new_pos = [l:delim.lnum, l:delim.cnum]
|
||||
" XXX spin this off
|
||||
" XXX very wrong for unicode
|
||||
let l:new_pos[1] += strdisplaywidth(l:delim.match) - 1
|
||||
|
||||
let l:new_pos[1] += matchup#delim#end_offset(l:delim)
|
||||
call matchup#pos#set_cursor(matchup#pos#next(l:new_pos))
|
||||
endfor
|
||||
|
||||
|
||||
@@ -43,19 +43,25 @@ endfunction
|
||||
function! matchup#pos#next(...) " {{{1
|
||||
let [l:lnum, l:cnum; l:rest] = s:parse_args(a:000)
|
||||
|
||||
return l:cnum < strlen(getline(l:lnum))
|
||||
\ ? [0, l:lnum, l:cnum+1, 0]
|
||||
\ : [0, l:lnum+1, 1, 0]
|
||||
let l:line = getline(l:lnum)
|
||||
let l:charlen = matchend(l:line[l:cnum-1:], '.')
|
||||
if l:cnum + l:charlen <= strlen(l:line)
|
||||
return [0, l:lnum, l:cnum + l:charlen, 0]
|
||||
else
|
||||
return [0, l:lnum+1, 1, 0]
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
function! matchup#pos#prev(...) " {{{1
|
||||
let [l:lnum, l:cnum; l:rest] = s:parse_args(a:000)
|
||||
|
||||
return l:cnum > 1
|
||||
\ ? [0, l:lnum, l:cnum-1, 0]
|
||||
\ : [0, max([l:lnum-1, 1]),
|
||||
\ max([strlen(getline(l:lnum-1)), 1]), 0]
|
||||
if l:cnum > 1
|
||||
return [0, l:lnum, match(getline(l:lnum)[0:l:cnum-2], '.$') + 1, 0]
|
||||
else
|
||||
return [0, max([l:lnum-1, 1]),
|
||||
\ max([strlen(getline(l:lnum-1)), 1]), 0]
|
||||
endif
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
|
||||
Reference in New Issue
Block a user