|
10 | 10 | const viewer = MultiFileDiffViewerState.get(); |
11 | 11 |
|
12 | 12 | function filterFileNode(file: TreeNode<FileTreeNodeData>): boolean { |
13 | | - return file.data.type === "file" && viewer.filterFile(file.data.file as FileDetails); |
| 13 | + return file.data.type === "file" && viewer.filterFile(file.data.file); |
14 | 14 | } |
15 | 15 |
|
16 | | - function ignoreInteraction(nodeInteractionEvent: Event): boolean { |
| 16 | + function shouldScrollToFile(nodeInteractionEvent: Event): boolean { |
17 | 17 | const element: HTMLElement = nodeInteractionEvent.target as HTMLElement; |
18 | 18 | // Don't scroll/etc. if we clicked the inner checkbox |
19 | 19 | return element.tagName.toLowerCase() !== "input"; |
|
22 | 22 | function focusFileDoubleClick(value: FileDetails): Attachment<HTMLElement> { |
23 | 23 | return (div) => { |
24 | 24 | const destroyDblclick = on(div, "dblclick", (event) => { |
25 | | - if (!ignoreInteraction(event)) return; |
| 25 | + if (!shouldScrollToFile(event)) return; |
26 | 26 | viewer.scrollToFile(value.index, { focus: true }); |
27 | 27 | viewer.setSelection(value, undefined); |
28 | 28 | if (!staticSidebar.current) { |
29 | 29 | viewer.layoutState.sidebarCollapsed = true; |
30 | 30 | } |
31 | 31 | }); |
32 | 32 | const destroyMousedown = on(div, "mousedown", (event) => { |
33 | | - if (!ignoreInteraction(event)) return; |
| 33 | + if (!shouldScrollToFile(event)) return; |
34 | 34 | if (event.detail === 2) { |
35 | 35 | // Don't select text on double click |
36 | 36 | event.preventDefault(); |
|
43 | 43 | }; |
44 | 44 | } |
45 | 45 |
|
46 | | - function nodeProps(data: FileTreeNodeData, toggleCollapse: () => void) { |
| 46 | + function nodeProps(data: FileTreeNodeData, collapsed: boolean, toggleCollapse: () => void) { |
47 | 47 | if (data.type === "file") { |
48 | 48 | const file = data.file; |
49 | 49 | return { |
50 | 50 | id: `file-tree-file-${file.index}`, |
51 | 51 | "data-selected": boolAttr(viewer.selection?.file.index === file.index), |
52 | | - onclick: (e: MouseEvent) => ignoreInteraction(e) && viewer.scrollToFile(file.index), |
53 | | - onkeydown: (e: KeyboardEvent) => e.key === "Enter" && ignoreInteraction(e) && viewer.scrollToFile(file.index), |
| 52 | + onclick: (e: MouseEvent) => shouldScrollToFile(e) && viewer.scrollToFile(file.index), |
| 53 | + onkeydown: (e: KeyboardEvent) => e.key === "Enter" && shouldScrollToFile(e) && viewer.scrollToFile(file.index), |
54 | 54 | [createAttachmentKey()]: focusFileDoubleClick(file), |
55 | 55 | }; |
56 | 56 | } else if (data.type === "directory") { |
57 | 57 | return { |
58 | 58 | onclick: toggleCollapse, |
59 | 59 | onkeydown: (e: KeyboardEvent) => e.key === "Enter" && toggleCollapse(), |
| 60 | + "aria-expanded": !collapsed, |
60 | 61 | }; |
61 | 62 | } |
62 | 63 | return {}; |
|
128 | 129 | tabindex="0" |
129 | 130 | class="btn-ghost focus:ring-2 focus:ring-primary/50 focus:outline-none focus:ring-inset" |
130 | 131 | style="padding-left: {node.depth}rem;" |
131 | | - {...nodeProps(node.data, toggleCollapse)} |
| 132 | + {...nodeProps(node.data, collapsed, toggleCollapse)} |
132 | 133 | > |
133 | 134 | {#if node.data.type === "file"} |
134 | 135 | {@render renderFileNode(node.data.file)} |
|
139 | 140 | {/snippet} |
140 | 141 | {#snippet childWrapper({ node, collapsed, children })} |
141 | 142 | {#if node.visibleChildren.length > 0} |
142 | | - <div |
143 | | - class="collapsible dir-header" |
144 | | - data-collapsed={boolAttr(collapsed || node.visibleChildren.length <= 0)} |
145 | | - data-type={node.data.type} |
146 | | - style="--tree-depth: {node.depth};" |
147 | | - > |
| 143 | + <div class="collapsible dir-header" data-collapsed={boolAttr(collapsed)} data-type={node.data.type} style="--tree-depth: {node.depth};"> |
148 | 144 | {@render children({ node })} |
149 | 145 | </div> |
150 | 146 | {/if} |
|
0 commit comments