WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit f74f904

Browse files
authored
Increase click area for file tree nodes (#56)
Also reduce the blue-500 spam * Increase click area for file tree nodes * fixes * Fix cursor inconsistency * Revert misleading cursor change * Passthrough pointer events on dir headers
1 parent 34d6f86 commit f74f904

File tree

7 files changed

+127
-105
lines changed

7 files changed

+127
-105
lines changed

web/src/lib/components/diff/concise-diff-view.svelte.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import {
1010
type ThemeRegistration,
1111
bundledThemes,
1212
} from "shiki";
13-
import { guessLanguageFromExtension, type MutableValue, type ReadableBoxedValues } from "$lib/util";
13+
import { guessLanguageFromExtension, type MutableValue } from "$lib/util";
1414
import type { IRawThemeSetting } from "shiki/textmate";
1515
import chroma from "chroma-js";
1616
import { getEffectiveGlobalTheme } from "$lib/theme.svelte";
1717
import { onDestroy } from "svelte";
1818
import { DEFAULT_THEME_LIGHT } from "$lib/global-options.svelte";
19-
import type { WritableBoxedValues } from "svelte-toolbelt";
19+
import type { ReadableBoxedValues, WritableBoxedValues } from "svelte-toolbelt";
2020
import type { Attachment } from "svelte/attachments";
2121
import { on } from "svelte/events";
2222
import { watch } from "runed";

web/src/lib/components/tree/index.svelte.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export type TreeNode<T> = {
1111
export interface TreeNodeView<T> extends TreeNode<T> {
1212
backingNode: TreeNode<T>;
1313
visibleChildren: TreeNodeView<T>[];
14+
depth: number;
1415
}
1516

1617
export interface TreeProps<T> {
@@ -115,18 +116,18 @@ export function collectAllNodes<T>(roots: TreeNode<T>[]): Set<TreeNode<T>> {
115116
// Keep any nodes where the filter passes and all their parents
116117
export function filteredView<T>(roots: TreeNode<T>[], filter: ((node: TreeNode<T>) => boolean) | null): Set<TreeNodeView<T>> {
117118
if (filter === null) {
118-
function walkDirect(node: TreeNode<T>): TreeNodeView<T> {
119-
return { ...node, backingNode: node, visibleChildren: node.children.map(walkDirect) };
119+
function walkDirect(node: TreeNode<T>, depth: number): TreeNodeView<T> {
120+
return { ...node, backingNode: node, visibleChildren: node.children.map((child) => walkDirect(child, depth + 1)), depth };
120121
}
121-
return new Set(roots.map((root) => walkDirect(root)));
122+
return new Set(roots.map((root) => walkDirect(root, 0)));
122123
}
123124

124-
function walkFiltered(node: TreeNode<T>): TreeNodeView<T> | null {
125+
function walkFiltered(node: TreeNode<T>, depth: number): TreeNodeView<T> | null {
125126
let pass = filter!(node);
126-
const nodeView: TreeNodeView<T> = { ...node, backingNode: node, visibleChildren: [] };
127+
const nodeView: TreeNodeView<T> = { ...node, backingNode: node, visibleChildren: [], depth };
127128

128129
for (const child of node.children) {
129-
const newChild = walkFiltered(child);
130+
const newChild = walkFiltered(child, depth + 1);
130131
if (newChild) {
131132
pass = true;
132133
nodeView.visibleChildren.push(newChild);
@@ -139,7 +140,7 @@ export function filteredView<T>(roots: TreeNode<T>[], filter: ((node: TreeNode<T
139140
const filtered: Set<TreeNodeView<T>> = new Set<TreeNodeView<T>>();
140141

141142
for (const root of roots) {
142-
const rootView = walkFiltered(root);
143+
const rootView = walkFiltered(root, 0);
143144
if (rootView) {
144145
filtered.add(rootView);
145146
}

web/src/lib/diff-viewer.svelte.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ const modifyStatusProps: FileStatusProps = {
231231
title: "Modified",
232232
};
233233
const renamedStatusProps: FileStatusProps = {
234-
iconClasses: "iconify octicon--file-moved-16 text-gray-600",
234+
iconClasses: "iconify octicon--file-moved-16 text-em-med",
235235
title: "Renamed",
236236
};
237237
const renamedModifiedStatusProps: FileStatusProps = {

web/src/lib/util.ts

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import type { FileStatus } from "./github.svelte";
33
import type { TreeNode } from "$lib/components/tree/index.svelte";
44
import type { BundledLanguage, SpecialLanguage } from "shiki";
55
import { onMount } from "svelte";
6-
import type { ReadableBox } from "svelte-toolbelt";
76
import { on } from "svelte/events";
87
import { type Attachment } from "svelte/attachments";
98

@@ -191,10 +190,15 @@ export function splitMultiFilePatch(patchContent: string): [BasicHeader, string]
191190
return patches;
192191
}
193192

194-
export type FileTreeNodeData = {
195-
data: FileDetails | string;
196-
type: "file" | "directory";
197-
};
193+
export type FileTreeNodeData =
194+
| {
195+
type: "file";
196+
file: FileDetails;
197+
}
198+
| {
199+
type: "directory";
200+
name: string;
201+
};
198202

199203
export function makeFileTree(paths: FileDetails[]): TreeNode<FileTreeNodeData>[] {
200204
if (paths.length === 0) {
@@ -203,24 +207,30 @@ export function makeFileTree(paths: FileDetails[]): TreeNode<FileTreeNodeData>[]
203207

204208
const root: TreeNode<FileTreeNodeData> = {
205209
children: [],
206-
data: { type: "directory", data: "" },
210+
data: { type: "directory", name: "" },
207211
};
208212

209213
for (const details of paths) {
210214
const parts = details.toFile.split("/");
211215
let current = root;
212216
for (let i = 0; i < parts.length; i++) {
213217
const part = parts[i];
214-
const existingChild = current.children.find((child) => child.data.data === part);
218+
const existingChild = current.children.find((child) => child.data.type === "directory" && child.data.name === part);
215219
if (existingChild) {
216220
current = existingChild;
217221
} else {
218222
const file = i === parts.length - 1;
219-
const data: FileDetails | string = file ? details : part;
220-
const type = file ? "file" : "directory";
221223
const newChild: TreeNode<FileTreeNodeData> = {
222224
children: [],
223-
data: { data, type },
225+
data: file
226+
? {
227+
type: "file",
228+
file: details,
229+
}
230+
: {
231+
type: "directory",
232+
name: part,
233+
},
224234
};
225235
current.children.push(newChild);
226236
current = newChild;
@@ -234,18 +244,18 @@ export function makeFileTree(paths: FileDetails[]): TreeNode<FileTreeNodeData>[]
234244
}
235245

236246
if (node.children.length === 1 && node.data.type === "directory" && node.children[0].data.type === "directory") {
237-
if (node.data.data !== "") {
238-
node.data.data = `${node.data.data}/${node.children[0].data.data}`;
247+
if (node.data.name !== "") {
248+
node.data.name = `${node.data.name}/${node.children[0].data.name}`;
239249
} else {
240-
node.data.data = node.children[0].data.data;
250+
node.data.name = node.children[0].data.name;
241251
}
242252
node.children = node.children[0].children;
243253
}
244254
}
245255

246256
mergeRedundantDirectories(root);
247257

248-
if (root.data.type === "directory" && root.data.data === "") {
258+
if (root.data.type === "directory" && root.data.name === "") {
249259
return root.children;
250260
}
251261
return [root];
@@ -482,8 +492,3 @@ export function animationFramePromise() {
482492
export async function yieldToBrowser() {
483493
await new Promise((resolve) => setTimeout(resolve, 0));
484494
}
485-
486-
// from bits-ui internals
487-
export type ReadableBoxedValues<T> = {
488-
[K in keyof T]: ReadableBox<T[K]>;
489-
};

web/src/routes/DiffSearch.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
autocomplete="off"
6262
style="padding-inline-end: {0.5 + controlsWidth / 16}rem;"
6363
/>
64-
<span aria-hidden="true" class="absolute top-1/2 left-1 iconify size-4 -translate-y-1/2 text-em-med octicon--search-16"></span>
64+
<span aria-hidden="true" class="absolute top-1/2 left-1.25 iconify size-4 -translate-y-1/2 text-em-med octicon--search-16"></span>
6565
<div class="absolute top-1/2 right-1 flex -translate-y-1/2 flex-row" bind:clientWidth={controlsWidth}>
6666
{#if viewer.searchQueryDebounced.current}
6767
{#await viewer.searchResults}

web/src/routes/FileHeader.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
const fileTreeElement = document.getElementById("file-tree-file-" + index);
2626
if (fileTreeElement) {
2727
popoverOpen = false;
28-
viewer.tree?.expandParents((node) => node.data === value);
28+
viewer.tree?.expandParents((node) => node.type === "file" && node.file === value);
2929
requestAnimationFrame(() => {
3030
fileTreeElement.focus();
3131
});

0 commit comments

Comments
 (0)