diff options
| author | Mitermayer Reis <mitermayer.reis@gmail.com> | 2019-09-13 22:29:36 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-09-13 22:29:36 -0700 |
| commit | 2bc93788e5a48e25ba6ed8f8a46e05cbd65489f3 (patch) | |
| tree | 4a694e3f668534c6d0c5f1356c034755b8172fa6 /autoload | |
| parent | e98b108ded5c906dde32db2f9856184e00dfc945 (diff) | |
| parent | 46fd3290d1c69fb394a79e5174e7c1aa69b885c0 (diff) | |
| download | vim-prettier-2bc93788e5a48e25ba6ed8f8a46e05cbd65489f3.tar.xz | |
Merge pull request #207 from prettier/issues/184-fixing-undo-step
Issues/184 fixing undo step
Diffstat (limited to 'autoload')
| -rw-r--r-- | autoload/prettier/job/async/neovim.vim | 4 | ||||
| -rw-r--r-- | autoload/prettier/utils/buffer.vim | 9 |
2 files changed, 10 insertions, 3 deletions
diff --git a/autoload/prettier/job/async/neovim.vim b/autoload/prettier/job/async/neovim.vim index 1cffe5c..28ecb8a 100644 --- a/autoload/prettier/job/async/neovim.vim +++ b/autoload/prettier/job/async/neovim.vim @@ -73,7 +73,7 @@ function! s:onExit(status, info, out, err) abort try silent exec 'sp '. escape(bufname(a:info.buf_nr), ' \') call nvim_buf_set_lines(a:info.buf_nr, a:info.start, a:info.end, 0, l:out) - write + noautocmd write catch call prettier#logging#error#log('PARSING_ERROR') finally @@ -91,7 +91,7 @@ function! s:onExit(status, info, out, err) abort " TODO " we should be auto saving in order to work similar to vim8 call nvim_buf_set_lines(a:info.buf_nr, a:info.start, a:info.end, 0, l:out) - write + noautocmd write endif let s:prettier_job_running = 0 diff --git a/autoload/prettier/utils/buffer.vim b/autoload/prettier/utils/buffer.vim index c22fec7..7bc7ab1 100644 --- a/autoload/prettier/utils/buffer.vim +++ b/autoload/prettier/utils/buffer.vim @@ -8,6 +8,12 @@ function! prettier#utils#buffer#replace(lines, startSelection, endSelection) abo return endif + " https://vim.fandom.com/wiki/Restore_the_cursor_position_after_undoing_text_change_made_by_a_script + " create a fake change entry and merge with undo stack prior to do formating + normal! ix + normal! x + try | silent undojoin | catch | endtry + " delete all lines on the current buffer silent! execute '%delete _' @@ -23,12 +29,13 @@ function! prettier#utils#buffer#replace(lines, startSelection, endSelection) abo " Restore view call winrestview(l:winview) + endfunction " Replace and save the buffer function! prettier#utils#buffer#replaceAndSave(lines, startSelection, endSelection) abort call prettier#utils#buffer#replace(a:lines, a:startSelection, a:endSelection) - write + noautocmd write endfunction " Returns 1 if content has changed |
