Use srings to describe exchange region comparison

... in preparation for things to come.
This commit is contained in:
Tom McDonald 2014-04-27 10:14:13 -04:00
parent 06f62c9f51
commit a55ebe1c8d

View File

@ -65,10 +65,10 @@ function! s:exchange_set(type, ...)
let reverse = 0 let reverse = 0
let cmp = s:compare(exchange1, exchange2) let cmp = s:compare(exchange1, exchange2)
if cmp == 0 if cmp == 'overlap'
echohl WarningMsg | echo "Exchange aborted: overlapping text" | echohl None echohl WarningMsg | echo "Exchange aborted: overlapping text" | echohl None
return s:exchange_clear() return s:exchange_clear()
elseif cmp > 0 elseif cmp == 'gt'
let reverse = 1 let reverse = 1
let [exchange1, exchange2] = [exchange2, exchange1] let [exchange1, exchange2] = [exchange2, exchange1]
endif endif
@ -132,10 +132,10 @@ function! s:compare(x, y)
" Compare two blockwise regions. " Compare two blockwise regions.
if xm == "\<C-V>" && ym == "\<C-V>" if xm == "\<C-V>" && ym == "\<C-V>"
if s:intersects(xs, xe, ys, ye) if s:intersects(xs, xe, ys, ye)
return 0 return 'overlap'
endif endif
let cmp = xs[2] - ys[2] let cmp = xs[2] - ys[2]
return cmp == 0 ? -1 : cmp return cmp <= 0 ? 'lt' : 'gt'
endif endif
" TODO: Compare a blockwise region with a linewise or characterwise region. " TODO: Compare a blockwise region with a linewise or characterwise region.
@ -145,10 +145,11 @@ function! s:compare(x, y)
" Compare two linewise or characterwise regions. " Compare two linewise or characterwise regions.
if (s:compare_pos(xs, ye) <= 0 && s:compare_pos(ys, xe) <= 0) || (s:compare_pos(ys, xe) <= 0 && s:compare_pos(xs, ye) <= 0) if (s:compare_pos(xs, ye) <= 0 && s:compare_pos(ys, xe) <= 0) || (s:compare_pos(ys, xe) <= 0 && s:compare_pos(xs, ye) <= 0)
" x and y overlap in buffer. " x and y overlap in buffer.
return 0 return 'overlap'
endif endif
return s:compare_pos(xs, ys) let cmp = s:compare_pos(xs, ys)
return cmp == 0 ? 'overlap' : cmp < 0 ? 'lt' : 'gt'
endfunction endfunction
function! s:compare_pos(x, y) function! s:compare_pos(x, y)