Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues/184 fixing undo step #207

Merged
merged 4 commits into from
Sep 14, 2019
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions autoload/prettier/job/async/neovim.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 8 additions & 1 deletion autoload/prettier/utils/buffer.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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 _'

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion plugin/prettier.vim
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,6 @@ nnoremap <silent> <Plug>(PrettierCliPath) :PrettierCliPath<CR>
augroup Prettier
autocmd!
if g:prettier#autoformat
autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue,*.yaml,*.html call prettier#Autoformat()
autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue,*.yaml,*.html noautocmd | call prettier#Autoformat()
endif
augroup end