This commit is contained in:
Joel Rocha 2021-12-13 15:56:27 -05:00 committed by GitHub
commit a5fcce3c13
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -33,16 +33,16 @@ fun! s:Rg(txt)
endfun endfun
fun! s:RgGetVisualSelection() fun! s:RgGetVisualSelection()
" Why is this not a built-in Vim script function?! " Why is this not a built-in Vim script function?!
let [line_start, column_start] = getpos("'<")[1:2] let [line_start, column_start] = getpos("'<")[1:2]
let [line_end, column_end] = getpos("'>")[1:2] let [line_end, column_end] = getpos("'>")[1:2]
let lines = getline(line_start, line_end) let lines = getline(line_start, line_end)
if len(lines) == 0 if len(lines) == 0
return '' return ''
endif endif
let lines[-1] = lines[-1][: column_end - (&selection == 'inclusive' ? 1 : 2)] let lines[-1] = lines[-1][: column_end - (&selection == 'inclusive' ? 1 : 2)]
let lines[0] = lines[0][column_start - 1:] let lines[0] = lines[0][column_start - 1:]
return join(lines, "\n") return join(lines, "\n")
endfun endfun
fun! s:RgSearchTerm(txt) fun! s:RgSearchTerm(txt)
@ -118,14 +118,20 @@ fun! s:RgRootDir()
let l:cwd = getcwd() let l:cwd = getcwd()
let l:dirs = split(getcwd(), '/') let l:dirs = split(getcwd(), '/')
for l:dir in reverse(copy(l:dirs)) "If NERDTree is open get the root of it to use as a path
for l:type in g:rg_root_types if exists('b:NERDTree')
let l:path = s:RgMakePath(l:dirs, l:dir) let l:root = b:NERDTree.root.path.str()
if s:RgHasFile(l:path.'/'.l:type) return l:root
return l:path else
endif for l:dir in reverse(copy(l:dirs))
for l:type in g:rg_root_types
let l:path = s:RgMakePath(l:dirs, l:dir)
if s:RgHasFile(l:path.'/'.l:type)
return l:path
endif
endfor
endfor endfor
endfor endif
return l:cwd return l:cwd
endfun endfun