From 41ebe9d96eb8b4043f30b7b7a43ef14e92a6aad1 Mon Sep 17 00:00:00 2001 From: Dmitry Vasilev Date: Wed, 16 Nov 2022 19:24:11 +0800 Subject: [PATCH] navigate async calls --- src/calltree.js | 44 +++++++++++++++++++++++++------------------- test/test.js | 3 +++ 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/src/calltree.js b/src/calltree.js index 01bf06a..74f3fb6 100644 --- a/src/calltree.js +++ b/src/calltree.js @@ -317,7 +317,7 @@ const arrow_down = state => { } else { const next = (n, path) => { - if(n == root_calltree_node(state)) { + if(n.id == 'calltree') { return null } const [parent, ...grandparents] = path @@ -334,10 +334,14 @@ const arrow_down = state => { next_node = next( current, - path_to_root(root_calltree_node(state), current) + path_to_root(state.calltree, current) ) } + if(next_node?.id == 'async_calls') { + next_node = next_node.children[0] + } + return next_node == null ? state : jump_calltree_node(state, next_node) @@ -348,26 +352,28 @@ const arrow_up = state => { if(current == root_calltree_node(state)) { return state } - const [parent] = path_to_root(root_calltree_node(state), current) + const [parent] = path_to_root(state.calltree, current) const child_index = parent.children.findIndex(c => c == current ) const next_child = parent.children[child_index - 1] + const last = node => { + if( + !is_expandable(node) + || !state.calltree_node_is_expanded[node.id] + || node.children == null + ) { + return node + } else { + return last(node.children[node.children.length - 1]) + } + } let next_node if(next_child == null) { - next_node = parent + next_node = parent.id == 'async_calls' + ? last(root_calltree_node(state)) + : parent } else { - const last = node => { - if( - !is_expandable(node) - || !state.calltree_node_is_expanded[node.id] - || node.children == null - ) { - return node - } else { - return last(node.children[node.children.length - 1]) - } - } next_node = last(next_child) } return jump_calltree_node(state, next_node) @@ -377,11 +383,11 @@ const arrow_left = state => { const current = state.current_calltree_node const is_expanded = state.calltree_node_is_expanded[current.id] if(!is_expandable(current) || !is_expanded) { - if(current != root_calltree_node(state)) { - const [parent] = path_to_root(root_calltree_node(state), current) - return jump_calltree_node(state, parent) - } else { + const [parent] = path_to_root(state.calltree, current) + if(parent.id == 'calltree' || parent.id == 'async_calls') { return state + } else { + return jump_calltree_node(state, parent) } } else { return toggle_expanded(state) diff --git a/test/test.js b/test/test.js index d549b95..acbe896 100644 --- a/test/test.js +++ b/test/test.js @@ -2355,6 +2355,9 @@ const y = x()` // Navigate logs const nav = COMMANDS.calltree.navigate_logs_position(expanded, 0) assert_equal(nav.state.current_calltree_node.is_log, true) + + const nav2 = COMMANDS.calltree.arrow_left(nav.state) + assert_equal(nav2.state.current_calltree_node.fn.name, 'fn2') }), ]