From 87f217f953b64103e8bef48980c0f002aa0f00c7 Mon Sep 17 00:00:00 2001 From: mitermayer Date: Sat, 14 Sep 2019 05:17:33 +0000 Subject: issues/184-fixing-undo-step - Fixing undo step - in order to bypass vimdefaults we can fake a change prior to formatting and merging that back to undostack operation --- autoload/prettier/utils/buffer.vim | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'autoload/prettier') diff --git a/autoload/prettier/utils/buffer.vim b/autoload/prettier/utils/buffer.vim index d09c568..821abda 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,6 +29,7 @@ function! prettier#utils#buffer#replace(lines, startSelection, endSelection) abo " Restore view call winrestview(l:winview) + endfunction " Replace and save the buffer -- cgit v1.3