diff --git a/src/driver/core/FileExplorer.ts b/src/driver/core/FileExplorer.ts index 53b6091..0f5fed7 100644 --- a/src/driver/core/FileExplorer.ts +++ b/src/driver/core/FileExplorer.ts @@ -213,11 +213,14 @@ export const setExpand: BoundMethodCreator<[TreeNode, boolean]> = dispatch => ( dispatch.call(focusNode, node, false) } -export const toggleNodeExpansion: BoundMethodCreator<[TreeNode, boolean]> = dispatch => ( - node, - skipScrollToNode, -) => { - visibleNodesGenerator.toggleExpand(node) +export const toggleNodeExpansion: BoundMethodCreator<[ + TreeNode, + { + skipScrollToNode?: boolean + recursive?: boolean + }, +]> = dispatch => (node, { skipScrollToNode = false, recursive = false }) => { + visibleNodesGenerator.toggleExpand(node, recursive) dispatch.call(focusNode, node, skipScrollToNode) tasksAfterRender.push(DOMHelper.focusFileExplorer) } @@ -235,25 +238,22 @@ export const onNodeClick: BoundMethodCreator<[ React.MouseEvent, TreeNode, ]> = dispatch => (event, node) => { - let preventDefault = true + const preventDefault = !(node.type === 'blob' && node.url?.includes('#')) + if (preventDefault) event.preventDefault() + if (node.type === 'tree') { - dispatch.call(toggleNodeExpansion, node, true) + dispatch.call(toggleNodeExpansion, node, { skipScrollToNode: true, recursive: event.shiftKey }) } else if (node.type === 'blob') { const [, { loadWithPJAX }] = dispatch.get() dispatch.call(focusNode, node, true) - if (node.url) { - if (node.url.includes('#')) { - preventDefault = false - } else { - loadWithPJAX(node.url) - } + if (node.url && !node.url.includes('#')) { + loadWithPJAX(node.url) } } else if (node.type === 'commit') { if (node.url) { window.open(node.url, '_blank') } } - if (preventDefault) event.preventDefault() } export const expandTo: BoundMethodCreator<[string[]]> = dispatch => currentPath => { diff --git a/src/utils/VisibleNodesGenerator.ts b/src/utils/VisibleNodesGenerator.ts index 3fa1f12..c4cbb5d 100644 --- a/src/utils/VisibleNodesGenerator.ts +++ b/src/utils/VisibleNodesGenerator.ts @@ -139,17 +139,31 @@ class L3 { this.l2 = l2 } - toggleExpand = (node: TreeNode) => { - this.setExpand(node, !this.expandedNodes.has(node.path)) + toggleExpand = (node: TreeNode, recursive?: boolean) => { + const expand = !this.expandedNodes.has(node.path) + if (recursive) { + const recursiveSetExpand = (node: TreeNode, expand: boolean) => { + this.barelySetExpand(node, expand) + node.contents?.forEach($node => recursiveSetExpand($node, expand)) + } + recursiveSetExpand(node, expand) + this.generateVisibleNodes() + } else { + this.setExpand(node, expand) + } } - setExpand = (node: TreeNode, expand: boolean) => { + barelySetExpand = (node: TreeNode, expand: boolean) => { if (expand && node.contents) { // only node with contents is expandable this.expandedNodes.add(node.path) } else { this.expandedNodes.delete(node.path) } + } + + setExpand = (node: TreeNode, expand: boolean) => { + this.barelySetExpand(node, expand) this.generateVisibleNodes() }