navigate async calls

This commit is contained in:
Dmitry Vasilev
2022-11-16 19:24:11 +08:00
parent f0f93229c7
commit 41ebe9d96e
2 changed files with 28 additions and 19 deletions

View File

@@ -317,7 +317,7 @@ const arrow_down = state => {
} else { } else {
const next = (n, path) => { const next = (n, path) => {
if(n == root_calltree_node(state)) { if(n.id == 'calltree') {
return null return null
} }
const [parent, ...grandparents] = path const [parent, ...grandparents] = path
@@ -334,10 +334,14 @@ const arrow_down = state => {
next_node = next( next_node = next(
current, 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 return next_node == null
? state ? state
: jump_calltree_node(state, next_node) : jump_calltree_node(state, next_node)
@@ -348,15 +352,11 @@ const arrow_up = state => {
if(current == root_calltree_node(state)) { if(current == root_calltree_node(state)) {
return 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 => const child_index = parent.children.findIndex(c =>
c == current c == current
) )
const next_child = parent.children[child_index - 1] const next_child = parent.children[child_index - 1]
let next_node
if(next_child == null) {
next_node = parent
} else {
const last = node => { const last = node => {
if( if(
!is_expandable(node) !is_expandable(node)
@@ -368,6 +368,12 @@ const arrow_up = state => {
return last(node.children[node.children.length - 1]) return last(node.children[node.children.length - 1])
} }
} }
let next_node
if(next_child == null) {
next_node = parent.id == 'async_calls'
? last(root_calltree_node(state))
: parent
} else {
next_node = last(next_child) next_node = last(next_child)
} }
return jump_calltree_node(state, next_node) return jump_calltree_node(state, next_node)
@@ -377,11 +383,11 @@ const arrow_left = state => {
const current = state.current_calltree_node const current = state.current_calltree_node
const is_expanded = state.calltree_node_is_expanded[current.id] const is_expanded = state.calltree_node_is_expanded[current.id]
if(!is_expandable(current) || !is_expanded) { if(!is_expandable(current) || !is_expanded) {
if(current != root_calltree_node(state)) { const [parent] = path_to_root(state.calltree, current)
const [parent] = path_to_root(root_calltree_node(state), current) if(parent.id == 'calltree' || parent.id == 'async_calls') {
return jump_calltree_node(state, parent)
} else {
return state return state
} else {
return jump_calltree_node(state, parent)
} }
} else { } else {
return toggle_expanded(state) return toggle_expanded(state)

View File

@@ -2355,6 +2355,9 @@ const y = x()`
// Navigate logs // Navigate logs
const nav = COMMANDS.calltree.navigate_logs_position(expanded, 0) const nav = COMMANDS.calltree.navigate_logs_position(expanded, 0)
assert_equal(nav.state.current_calltree_node.is_log, true) 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')
}), }),
] ]