mirror of
https://github.com/chenasraf/vim-matchup.git
synced 2026-05-18 01:38:57 +00:00
Update motions and objects for &selection
This commit is contained in:
@@ -173,7 +173,20 @@ function! matchup#motion#find_matching_pair(visual, down) " {{{1
|
||||
endif
|
||||
endif
|
||||
|
||||
call matchup#pos#set_cursor(l:delim.lnum, l:column)
|
||||
let l:lnum = l:delim.lnum
|
||||
|
||||
" make adjustments for selection option 'exclusive
|
||||
if l:forward && a:visual && &selection ==# 'exclusive'
|
||||
let [l:lnum, l:column] = matchup#pos#next_eol(l:lnum, l:column)[1:2]
|
||||
endif
|
||||
if !l:forward && l:is_oper && &selection ==# 'exclusive'
|
||||
normal! o
|
||||
call matchup#pos#set_cursor(matchup#pos#next_eol(
|
||||
\ matchup#pos#get_cursor()))
|
||||
normal! o
|
||||
endif
|
||||
|
||||
call matchup#pos#set_cursor(l:lnum, l:column)
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
@@ -181,7 +194,9 @@ function! matchup#motion#find_unmatched(visual, down) " {{{1
|
||||
call matchup#perf#tic('motion#find_unmatched')
|
||||
|
||||
let l:count = v:count1
|
||||
let l:exclusive = !empty(get(s:, 'v_operator', ''))
|
||||
|
||||
let l:is_oper = !empty(get(s:, 'v_operator', ''))
|
||||
let l:exclusive = l:is_oper
|
||||
\ && g:v_motion_force !=# 'v' && g:v_motion_force !=# "\<c-v>"
|
||||
|
||||
if a:visual
|
||||
@@ -232,6 +247,19 @@ function! matchup#motion#find_unmatched(visual, down) " {{{1
|
||||
normal! o
|
||||
endif
|
||||
|
||||
" handle selection option 'exclusive' going backwards
|
||||
if !a:down && l:is_oper && &selection ==# 'exclusive'
|
||||
normal! o
|
||||
call matchup#pos#set_cursor(matchup#pos#next_eol(
|
||||
\ matchup#pos#get_cursor()))
|
||||
normal! o
|
||||
endif
|
||||
|
||||
" handle selection option 'exclusive' going forwards
|
||||
if a:down && l:is_oper && &selection ==# 'exclusive'
|
||||
let l:new_pos = matchup#pos#next_eol(l:new_pos)[1:2]
|
||||
endif
|
||||
|
||||
normal! m`
|
||||
call matchup#pos#set_cursor(l:new_pos)
|
||||
|
||||
@@ -281,6 +309,11 @@ function! matchup#motion#jump_inside(visual) " {{{1
|
||||
let l:new_pos = matchup#pos#prev(l:new_pos)
|
||||
endif
|
||||
|
||||
" handle selection option 'exclusive' (motion only goes forwards)
|
||||
if a:visual && &selection ==# 'exclusive'
|
||||
let l:new_pos = matchup#pos#next_eol(l:new_pos)
|
||||
endif
|
||||
|
||||
normal! m`
|
||||
call matchup#pos#set_cursor(l:new_pos)
|
||||
endfunction
|
||||
|
||||
@@ -39,6 +39,21 @@ function! matchup#pos#val(...) " {{{1
|
||||
return 100000*l:lnum + min([l:cnum, 90000])
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
function! matchup#pos#next_eol(...) " {{{1
|
||||
let [l:lnum, l:cnum; l:rest] = s:parse_args(a:000)
|
||||
|
||||
if l:cnum > strlen(getline(l:lnum))
|
||||
return [0, l:lnum+1, 1, 0]
|
||||
endif
|
||||
|
||||
let l:next = matchup#pos#next(l:lnum, l:cnum)
|
||||
if l:next[1] > l:lnum
|
||||
return [0, l:lnum, l:cnum+1, 0]
|
||||
endif
|
||||
return l:next
|
||||
endfunction
|
||||
|
||||
" }}}1
|
||||
function! matchup#pos#next(...) " {{{1
|
||||
let [l:lnum, l:cnum; l:rest] = s:parse_args(a:000)
|
||||
|
||||
@@ -165,12 +165,7 @@ function! matchup#text_obj#delimited(is_inner, visual, type) " {{{1
|
||||
\ : 'v'
|
||||
|
||||
if &selection ==# 'exclusive'
|
||||
" TODO this should be a function similar to pos#next
|
||||
let [l:l2, l:c2] = l:c2 > strlen(getline(l:l2))
|
||||
\ ? [l:l2+1, 1]
|
||||
\ : matchup#pos#next(l:l2, l:c2)[1] > l:l2
|
||||
\ ? [l:l2, l:c2+1]
|
||||
\ : matchup#pos#next(l:l2, l:c2)[1:2]
|
||||
let [l:l2, l:c2] = matchup#pos#next_eol(l:l2, l:c2)[1:2]
|
||||
endif
|
||||
|
||||
" apply selection
|
||||
|
||||
Reference in New Issue
Block a user