mirror of
https://github.com/Raimondi/delimitMate.git
synced 2025-12-07 13:14:35 +08:00
Use GetChar*Cursor() instead of byte indexes.
This commit is contained in:
@@ -14,7 +14,7 @@ function! delimitMate#ShouldJump() "{{{
|
|||||||
" Returns 1 if the next character is a closing delimiter.
|
" Returns 1 if the next character is a closing delimiter.
|
||||||
let col = col('.')
|
let col = col('.')
|
||||||
let lcol = col('$')
|
let lcol = col('$')
|
||||||
let char = getline('.')[col - 1]
|
let char = delimitMate#GetCharUnderCursor()
|
||||||
|
|
||||||
" Closing delimiter on the right.
|
" Closing delimiter on the right.
|
||||||
for cdel in b:_l_delimitMate_right_delims + b:_l_delimitMate_quotes_list
|
for cdel in b:_l_delimitMate_right_delims + b:_l_delimitMate_quotes_list
|
||||||
@@ -249,10 +249,10 @@ function! delimitMate#SkipDelim(char) "{{{
|
|||||||
let col = col('.') - 1
|
let col = col('.') - 1
|
||||||
let line = getline('.')
|
let line = getline('.')
|
||||||
if col > 0
|
if col > 0
|
||||||
let cur = line[col]
|
let cur = delimitMate#GetCharUnderCursor()
|
||||||
let pre = line[col-1]
|
let pre = delimitMate#GetCharBeforeCursor()
|
||||||
else
|
else
|
||||||
let cur = line[col]
|
let cur = delimitMate#GetCharUnderCursor()
|
||||||
let pre = ""
|
let pre = ""
|
||||||
endif
|
endif
|
||||||
if pre == "\\"
|
if pre == "\\"
|
||||||
@@ -305,22 +305,21 @@ function! delimitMate#QuoteDelim(char) "{{{
|
|||||||
if delimitMate#IsForbidden(a:char)
|
if delimitMate#IsForbidden(a:char)
|
||||||
return a:char
|
return a:char
|
||||||
endif
|
endif
|
||||||
let line = getline('.')
|
|
||||||
let col = col('.') - 2
|
|
||||||
if line[col] == "\\"
|
if line[col] == "\\"
|
||||||
" Seems like a escaped character, insert one quotation mark.
|
" Seems like a escaped character, insert one quotation mark.
|
||||||
return a:char
|
return a:char
|
||||||
elseif line[col + 1] == a:char &&
|
"elseif line[col + 1] == a:char &&
|
||||||
|
elseif delimitMate#GetCharUnderCursor() == a:char &&
|
||||||
\ index(b:_l_delimitMate_nesting_quotes, a:char) < 0
|
\ index(b:_l_delimitMate_nesting_quotes, a:char) < 0
|
||||||
" Get out of the string.
|
" Get out of the string.
|
||||||
return a:char . delimitMate#Del()
|
return a:char . delimitMate#Del()
|
||||||
elseif (line[col] =~ '\w' && a:char == "'") ||
|
elseif (delimitMate#GetCharBeforeCursor() =~ '\w' && a:char == "'") ||
|
||||||
\ (b:_l_delimitMate_smart_quotes &&
|
\ (b:_l_delimitMate_smart_quotes &&
|
||||||
\ (line[col] =~ '\w' ||
|
\ (delimitMate#GetCharBeforeCursor() =~ '\w' ||
|
||||||
\ line[col + 1] =~ '\w'))
|
\ delimitMate#GetCharUnderCursor() =~ '\w'))
|
||||||
" Seems like an apostrophe or a smart quote case, insert a single quote.
|
" Seems like an apostrophe or a smart quote case, insert a single quote.
|
||||||
return a:char
|
return a:char
|
||||||
elseif (line[col] == a:char && line[col + 1 ] != a:char) && b:_l_delimitMate_smart_quotes
|
elseif (delimitMate#GetCharBeforeCursor() == a:char && delimitMate#GetCharUnderCursor() != a:char) && b:_l_delimitMate_smart_quotes
|
||||||
" Seems like we have an unbalanced quote, insert one quotation mark and jump to the middle.
|
" Seems like we have an unbalanced quote, insert one quotation mark and jump to the middle.
|
||||||
call insert(b:_l_delimitMate_buffer, a:char)
|
call insert(b:_l_delimitMate_buffer, a:char)
|
||||||
return delimitMate#WriteAfter(a:char)
|
return delimitMate#WriteAfter(a:char)
|
||||||
@@ -336,9 +335,7 @@ function! delimitMate#JumpOut(char) "{{{
|
|||||||
if delimitMate#IsForbidden(a:char)
|
if delimitMate#IsForbidden(a:char)
|
||||||
return a:char
|
return a:char
|
||||||
endif
|
endif
|
||||||
let line = getline('.')
|
if delimitMate#GetCharUnderCursor() == a:char
|
||||||
let col = col('.')-2
|
|
||||||
if line[col+1] == a:char
|
|
||||||
return a:char . delimitMate#Del()
|
return a:char . delimitMate#Del()
|
||||||
else
|
else
|
||||||
return a:char
|
return a:char
|
||||||
@@ -353,7 +350,7 @@ function! delimitMate#JumpAny(key) " {{{
|
|||||||
return a:key
|
return a:key
|
||||||
endif
|
endif
|
||||||
" Let's get the character on the right.
|
" Let's get the character on the right.
|
||||||
let char = getline('.')[col('.')-1]
|
let char = delimitMate#GetCharUnderCursor()
|
||||||
if char == " "
|
if char == " "
|
||||||
" Space expansion.
|
" Space expansion.
|
||||||
"let char = char . getline('.')[col('.')] . delimitMate#Del()
|
"let char = char . getline('.')[col('.')] . delimitMate#Del()
|
||||||
@@ -371,13 +368,10 @@ function! delimitMate#JumpAny(key) " {{{
|
|||||||
endfunction " delimitMate#JumpAny() }}}
|
endfunction " delimitMate#JumpAny() }}}
|
||||||
|
|
||||||
function! delimitMate#JumpMany() " {{{
|
function! delimitMate#JumpMany() " {{{
|
||||||
let line = getline('.')[col('.') - 1 : ]
|
let line = split(getline('.')[col('.') - 1 : ], '\zs')
|
||||||
let len = len(line)
|
|
||||||
let rights = ""
|
let rights = ""
|
||||||
let found = 0
|
let found = 0
|
||||||
let i = 0
|
for char in line
|
||||||
while i < len
|
|
||||||
let char = line[i]
|
|
||||||
if index(b:_l_delimitMate_quotes_list, char) >= 0 ||
|
if index(b:_l_delimitMate_quotes_list, char) >= 0 ||
|
||||||
\ index(b:_l_delimitMate_right_delims, char) >= 0
|
\ index(b:_l_delimitMate_right_delims, char) >= 0
|
||||||
let rights .= "\<Right>"
|
let rights .= "\<Right>"
|
||||||
@@ -387,8 +381,7 @@ function! delimitMate#JumpMany() " {{{
|
|||||||
else
|
else
|
||||||
break
|
break
|
||||||
endif
|
endif
|
||||||
let i += 1
|
endfor
|
||||||
endwhile
|
|
||||||
if found == 1
|
if found == 1
|
||||||
return rights
|
return rights
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user