From c194baf8b30a27ed0075ca0eece270431bdaa913 Mon Sep 17 00:00:00 2001 From: Victor S Date: Wed, 4 Oct 2023 19:25:19 -0300 Subject: refactor: split range getter into two parts Split the function that returns the visual selection range into two parts that return the start and the end of the range respectively, and use them in the CLI-command composer. This is part of a plan to use a general object with details about flags to compose the CLI command. --- autoload/prettier/utils/buffer.vim | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'autoload/prettier/utils/buffer.vim') diff --git a/autoload/prettier/utils/buffer.vim b/autoload/prettier/utils/buffer.vim index 3125bcc..922a0db 100644 --- a/autoload/prettier/utils/buffer.vim +++ b/autoload/prettier/utils/buffer.vim @@ -61,10 +61,12 @@ function! s:getCharPosition(line, col) abort return line2byte(a:line) + (a:col - 2) endfun -" Returns [start, end] byte range when on visual mode -function! prettier#utils#buffer#getCharRange(startSelection, endSelection) abort - let l:range = [] - call add(l:range, s:getCharPosition(a:startSelection, col("'<"))) - call add(l:range, s:getCharPosition(a:endSelection, col("'>"))) - return l:range +" Return the start byte when on visual mode +function! prettier#utils#buffer#getCharRangeStart(startSelection) abort + return s:getCharPosition(a:startSelection, col("'<")) +endfunction + +" Return the end byte when on visual mode +function! prettier#utils#buffer#getCharRangeEnd(endSelection) abort + return s:getCharPosition(a:endSelection, col("'>")) endfunction -- cgit v1.3