diff options
Diffstat (limited to 'autoload/prettier/utils')
| -rw-r--r-- | autoload/prettier/utils/buffer.vim | 14 | ||||
| -rw-r--r-- | autoload/prettier/utils/version.vim | 25 |
2 files changed, 33 insertions, 6 deletions
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 diff --git a/autoload/prettier/utils/version.vim b/autoload/prettier/utils/version.vim new file mode 100644 index 0000000..3cbbb73 --- /dev/null +++ b/autoload/prettier/utils/version.vim @@ -0,0 +1,25 @@ +" Returns 1 if the first argument is the greater version, returns 0 if the +" arguments are the same version, or returns -1 if the first argument is the +" lesser version. +function! prettier#utils#version#Compare_versions(a, b) abort + let [l:a_major, l:a_minor, l:a_patch; l:rest] = a:a->split('\D') + \ ->map('str2nr(v:val)') + let [l:b_major, l:b_minor, l:b_patch; l:rest] = a:b->split('\D') + \ ->map('str2nr(v:val)') + let l:is_a_greater = + \ l:a_major > l:b_major + \ || (l:a_major == l:b_major && l:a_minor > l:b_minor) + \ || (l:a_major == l:b_major && l:a_minor == l:b_minor + \ && l:a_patch > l:b_patch) + let l:is_a_equal_b = + \ l:a_major == l:b_major + \ && l:a_minor == l:b_minor + \ && l:a_patch == l:b_patch + return l:is_a_greater ? 1 : (l:is_a_equal_b ? 0 : -1) +endfunction + +" Returns 1 if the first argument is greater than or equal to the second, +" otherwise returns 0. +function! prettier#utils#version#Is_greater_or_equal_version(a, b) abort + return prettier#utils#version#Compare_versions(a:a, a:b) != -1 +endfunction |
