Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions autoload/codepainter.vim
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ func! s:MarkSelection(start_pos, end_pos, v_mode) abort
endif
endfunc

func! s:RestoreCursorPos(new_pos)
" Restore cursor position
if g:has_nvim
if v:false
call feedkeys("\<Esc>", 'n') " Ensure visual mode is properly exited
call timer_start(0, {-> setpos('.', a:new_pos)})
else
call nvim_win_set_cursor(0, [a:new_pos[1], a:new_pos[2]-1])
endif
else
call setpos('.', a:new_pos)
endif
endf
func! codepainter#paintText(v_mode) range abort
"mark text
let l:start_pos = getpos("'<")
Expand All @@ -120,6 +133,8 @@ func! codepainter#paintText(v_mode) range abort
"if it wasn't stored, we mark it
if !has_key(g:marks, l:start_pos[1] + index)
call s:MarkSelection(l:start_pos, l:end_pos, a:v_mode)
" Restore cursor position
call s:RestoreCursorPos(l:end_pos)
return
endif
for known_mark in g:marks[l:start_pos[1] + index]
Expand All @@ -139,6 +154,9 @@ func! codepainter#paintText(v_mode) range abort
if l:found == 0
call s:MarkSelection(l:start_pos, l:end_pos, a:v_mode)
endif

" Restore cursor position
call s:RestoreCursorPos(l:end_pos)
endfunc

func! codepainter#EraseAll() abort
Expand Down