Update motions and objects for &selection

This commit is contained in:
Andy K. Massimino
2017-11-30 14:19:06 -05:00
parent 6882d9c2c7
commit c93dbac19c
3 changed files with 51 additions and 8 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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