Adjust cursor position to offset text length

Fixes #16
This commit is contained in:
Tom McDonald 2015-08-01 15:21:17 -04:00
parent e12149d5d6
commit bae89cbde9

View File

@ -41,10 +41,8 @@ function! s:exchange(x, y, reverse, expand)
call winrestview(view) call winrestview(view)
if a:reverse if !a:expand
call cursor(a:x.start.line, a:x.start.column) call s:fix_cursor(a:x, a:y, a:reverse)
else
call cursor(a:y.start.line, a:y.start.column)
endif endif
let &selection = selection let &selection = selection
@ -54,6 +52,20 @@ function! s:exchange(x, y, reverse, expand)
call s:restore_reg('+', reg_plus) call s:restore_reg('+', reg_plus)
endfunction endfunction
function! s:fix_cursor(x, y, reverse)
if a:reverse
call cursor(a:x.start.line, a:x.start.column)
else
if a:x.start.line == a:y.start.line
let horizontal_offset = a:x.end.column - a:y.end.column
call cursor(a:x.start.line, a:x.start.column - horizontal_offset)
else
let vertical_offset = a:x.end.line - a:y.end.line
call cursor(a:x.start.line - vertical_offset, a:x.start.column)
endif
endif
endfunction
function! s:reindent(start, lines, new_indent) function! s:reindent(start, lines, new_indent)
if (exists('b:exchange_indent') ? b:exchange_indent : g:exchange_indent) == '==' if (exists('b:exchange_indent') ? b:exchange_indent : g:exchange_indent) == '=='
let lnum = nextnonblank(a:start) let lnum = nextnonblank(a:start)