diff options
| author | mitermayer <mitermayer.reis@gmail.com> | 2018-05-04 09:37:26 -0700 |
|---|---|---|
| committer | mitermayer <mitermayer.reis@gmail.com> | 2019-08-25 21:11:49 -0700 |
| commit | 33660a2f98fa0fde5ef55d0dff55b08cc0225a0f (patch) | |
| tree | 9ffe514afbee76d16144dc16e8afae71db67b11c /autoload/prettier/utils | |
| parent | a44e1963c9dccc72f9cd343b7763f1c8907b39e7 (diff) | |
| download | vim-prettier-33660a2f98fa0fde5ef55d0dff55b08cc0225a0f.tar.xz | |
Moving formating ultils to buffer module
- moving formating utils to buffer module to make it easier to interact
and test
Diffstat (limited to 'autoload/prettier/utils')
| -rw-r--r-- | autoload/prettier/utils/buffer.vim | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/autoload/prettier/utils/buffer.vim b/autoload/prettier/utils/buffer.vim new file mode 100644 index 0000000..06fd7ff --- /dev/null +++ b/autoload/prettier/utils/buffer.vim @@ -0,0 +1,29 @@ +function! prettier#utils#buffer#replace(lines, startSelection, endSelection) abort + " store view + let l:winview = winsaveview() + let l:newBuffer = prettier#utils#buffer#createBufferFromUpdatedLines(a:lines, a:startSelection, a:endSelection) + + " we should not replace contents if the newBuffer is empty + if empty(l:newBuffer) + return + endif + + " delete all lines on the current buffer + silent! execute len(l:newBuffer) . ',' . line('$') . 'delete _' + + " replace all lines from the current buffer with output from prettier + call setline(1, l:newBuffer) + + " Restore view + call winrestview(l:winview) +endfunction + +" Returns 1 if content has changed +function! prettier#utils#buffer#willUpdatedLinesChangeBuffer(lines, start, end) abort + return getbufline(bufnr('%'), 1, line('$')) == prettier#utils#buffer#createBufferFromUpdatedLines(a:lines, a:start, a:end) ? 0 : 1 +endfunction + +" Returns a new buffer with lines replacing start and end of the contents of the current buffer +function! prettier#utils#buffer#createBufferFromUpdatedLines(lines, start, end) abort + return getbufline(bufnr('%'), 1, a:start - 1) + a:lines + getbufline(bufnr('%'), a:end + 1, '$') +endfunction |
