Skip to content

Commit

Permalink
Resotre cursor position when sorting
Browse files Browse the repository at this point in the history
Also copy the content when sorting

Ref #67
  • Loading branch information
liuchengxu committed Apr 26, 2019
1 parent 839f6ba commit 1ea2ca7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
9 changes: 8 additions & 1 deletion autoload/vista.vim
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@ function! vista#Sort() abort
endif
let provider = t:vista.provider
let cache = vista#executive#{provider}#Cache()
call vista#sidebar#Reload(vista#viewer#Render(cache))

let cursor_position = getpos('.')

call vista#sidebar#Reload(cache)

if cursor_position != getpos('.')
call setpos('.', cursor_position)
endif
endfunction

function! vista#RunForNearestMethodOrFunction() abort
Expand Down
2 changes: 1 addition & 1 deletion autoload/vista/executive/coc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ function! s:Dispatch(F, ...) abort
endfunction

function! vista#executive#coc#Cache() abort
return get(s:, 'cache', {})
return get(s:, 'data', {})
endfunction

" Internal public APIs
Expand Down
2 changes: 1 addition & 1 deletion autoload/vista/executive/ctags.vim
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ function! s:Dispatch(F, ...) abort
endfunction

function! vista#executive#ctags#Cache() abort
return get(s:, 'cache', {})
return get(s:, 'data', {})
endfunction

" Run ctags given the cmd synchronously
Expand Down
2 changes: 1 addition & 1 deletion autoload/vista/renderer/default.vim
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function! s:RenderScopeless(scope_less, rows) abort
let lines = scope_less[kind]

if get(t:vista, 'sort', v:false)
call sort(lines, function('s:Compare'))
let lines = sort(copy(lines), function('s:Compare'))
endif

for line in lines
Expand Down
8 changes: 4 additions & 4 deletions autoload/vista/renderer/kind.vim
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ function! s:viewer.render() abort
" Parent
call add(self.rows, parent)

if get(t:vista, 'sort', v:false)
call sort(v, function('s:Compare'))
endif

if !empty(v)

if get(t:vista, 'sort', v:false)
let v = sort(copy(v), function('s:Compare'))
endif

" Children
for i in v
if len(i) > 0
Expand Down

0 comments on commit 1ea2ca7

Please sign in to comment.