Skip to content

Commit

Permalink
Ensure that the node is collapsed prior to reveal
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdalisue committed Aug 26, 2023
1 parent 68ed0fa commit 9e491f6
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions autoload/fern/internal/node.vim
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,12 @@ function! fern#internal#node#reveal(key, nodes, provider, comparator, token) abo
return s:Promise.resolve(a:nodes)
endif
let l:Profile = fern#profile#start('fern#internal#node#reveal')
return s:expand_recursively(0, a:key, a:nodes, a:provider, a:comparator, a:token)
let node = fern#internal#node#find(a:key[:0], a:nodes)
if node is# v:null || node.status is# s:STATUS_NONE
return s:Promise.resolve(a:nodes)
endif
return fern#internal#node#collapse(node, a:nodes, a:provider, a:comparator, a:token)
\.then({ ns -> s:expand_recursively(0, a:key, ns, a:provider, a:comparator, a:token) })
\.finally({ -> Profile() })
endfunction

Expand Down Expand Up @@ -236,14 +241,13 @@ function! s:extend(key, nodes, new_nodes) abort
endfunction

function! s:expand_recursively(index, key, nodes, provider, comparator, token) abort
if a:index >= len(a:key)
return s:Promise.resolve(a:nodes)
endif
let node = fern#internal#node#find(a:key[:a:index], a:nodes)
if node is# v:null || node.status is# s:STATUS_NONE
return s:Promise.resolve(a:nodes)
endif
return fern#internal#node#expand(node, a:nodes, a:provider, a:comparator, a:token)
\.then({ ns -> s:Lambda.if(
\ a:index < len(a:key) - 1,
\ { -> s:expand_recursively(a:index + 1, a:key, ns, a:provider, a:comparator, a:token) },
\ { -> ns },
\ )})
\.then({ ns -> s:expand_recursively(a:index + 1, a:key, ns, a:provider, a:comparator, a:token) })
endfunction

0 comments on commit 9e491f6

Please sign in to comment.