Skip to content

Commit ea403f5

Browse files
committed
fixes
1 parent cf98799 commit ea403f5

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

web/src/routes/Sidebar.svelte

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
const viewer = MultiFileDiffViewerState.get();
1111
1212
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);
1414
}
1515
16-
function ignoreInteraction(nodeInteractionEvent: Event): boolean {
16+
function shouldScrollToFile(nodeInteractionEvent: Event): boolean {
1717
const element: HTMLElement = nodeInteractionEvent.target as HTMLElement;
1818
// Don't scroll/etc. if we clicked the inner checkbox
1919
return element.tagName.toLowerCase() !== "input";
@@ -22,15 +22,15 @@
2222
function focusFileDoubleClick(value: FileDetails): Attachment<HTMLElement> {
2323
return (div) => {
2424
const destroyDblclick = on(div, "dblclick", (event) => {
25-
if (!ignoreInteraction(event)) return;
25+
if (!shouldScrollToFile(event)) return;
2626
viewer.scrollToFile(value.index, { focus: true });
2727
viewer.setSelection(value, undefined);
2828
if (!staticSidebar.current) {
2929
viewer.layoutState.sidebarCollapsed = true;
3030
}
3131
});
3232
const destroyMousedown = on(div, "mousedown", (event) => {
33-
if (!ignoreInteraction(event)) return;
33+
if (!shouldScrollToFile(event)) return;
3434
if (event.detail === 2) {
3535
// Don't select text on double click
3636
event.preventDefault();
@@ -43,20 +43,21 @@
4343
};
4444
}
4545
46-
function nodeProps(data: FileTreeNodeData, toggleCollapse: () => void) {
46+
function nodeProps(data: FileTreeNodeData, collapsed: boolean, toggleCollapse: () => void) {
4747
if (data.type === "file") {
4848
const file = data.file;
4949
return {
5050
id: `file-tree-file-${file.index}`,
5151
"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),
5454
[createAttachmentKey()]: focusFileDoubleClick(file),
5555
};
5656
} else if (data.type === "directory") {
5757
return {
5858
onclick: toggleCollapse,
5959
onkeydown: (e: KeyboardEvent) => e.key === "Enter" && toggleCollapse(),
60+
"aria-expanded": !collapsed,
6061
};
6162
}
6263
return {};
@@ -128,7 +129,7 @@
128129
tabindex="0"
129130
class="btn-ghost focus:ring-2 focus:ring-primary/50 focus:outline-none focus:ring-inset"
130131
style="padding-left: {node.depth}rem;"
131-
{...nodeProps(node.data, toggleCollapse)}
132+
{...nodeProps(node.data, collapsed, toggleCollapse)}
132133
>
133134
{#if node.data.type === "file"}
134135
{@render renderFileNode(node.data.file)}
@@ -139,12 +140,7 @@
139140
{/snippet}
140141
{#snippet childWrapper({ node, collapsed, children })}
141142
{#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};">
148144
{@render children({ node })}
149145
</div>
150146
{/if}

0 commit comments

Comments
 (0)