Skip to content

Commit

Permalink
fix(snippets): fix end selection when selection is exclusive
Browse files Browse the repository at this point in the history
  • Loading branch information
chemzqm committed May 25, 2022
1 parent 6346826 commit f302272
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
25 changes: 17 additions & 8 deletions autoload/coc/snippet.vim
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,29 @@ function! coc#snippet#disable()
silent! execute 'sunmap <buffer> <silent> '.nextkey
endfunction

function! coc#snippet#select(position, text) abort
function! coc#snippet#select(start, end, text) abort
if pumvisible()
call coc#_cancel()
endif
if mode() == 's'
call feedkeys("\<Esc>", 'in')
endif
let cursor = coc#snippet#to_cursor(a:position)
call cursor([cursor[0], cursor[1] - (&selection !~# 'exclusive')])
let len = strchars(a:text) - (&selection !~# 'exclusive')
let cmd = ''
let cmd .= mode()[0] ==# 'i' ? "\<Esc>l" : ''
let cmd .= printf('v%s', len > 0 ? len . 'h' : '')
let cmd .= "o\<C-g>"
if &selection ==# 'exclusive'
let cursor = coc#snippet#to_cursor(a:start)
call cursor([cursor[0], cursor[1]])
let cmd = ''
let cmd .= mode()[0] ==# 'i' ? "\<Esc>".(col('.') == 1 ? '' : 'l') : ''
let cmd .= printf('v%s', strchars(a:text) . 'l')
let cmd .= "\<C-g>"
else
let cursor = coc#snippet#to_cursor(a:end)
call cursor([cursor[0], cursor[1] - 1])
let len = strchars(a:text) - 1
let cmd = ''
let cmd .= mode()[0] ==# 'i' ? "\<Esc>l" : ''
let cmd .= printf('v%s', len > 0 ? len . 'h' : '')
let cmd .= "o\<C-g>"
endif
call feedkeys(cmd, 'n')
endfunction

Expand Down
2 changes: 1 addition & 1 deletion src/snippets/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export class SnippetSession {
let { range, value } = placeholder
let { nvim } = this
if (value.length > 0) {
await nvim.call('coc#snippet#select', [range.end, value])
await nvim.call('coc#snippet#select', [range.start, range.end, value])
} else {
await nvim.call('coc#snippet#move', [range.start])
}
Expand Down

0 comments on commit f302272

Please sign in to comment.