mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
feat: recursive toggle expand
This commit is contained in:
parent
56a97040d8
commit
fde2ad90df
2 changed files with 31 additions and 17 deletions
|
|
@ -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<HTMLElement, 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 => {
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue