8000 feat: repl: Select top file in file UI when we can't match · cmcaine/svelte.dev@029fdce · GitHub
[go: up one dir, main page]

Skip to content

Commit 029fdce

Browse files
committed
feat: repl: Select top file in file UI when we can't match
Follows up on sveltejs#1297.
1 parent 0485be4 commit 029fdce

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

packages/repl/src/lib/Workspace.svelte.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,23 @@ export class Workspace {
429429
if (matching_file) {
430430
this.#select(matching_file as File);
431431
} else {
432-
this.#select(first);
432+
// Try to select the first file in the file selector thing.
433+
// The file selector lists files in the root directory after all files in
434+
// other directories.
435+
const top_file = files.filter(is_file).sort((a, b) => {
436+
const in_root_dir = x => x.basename === x.name
437+
438+
if (in_root_dir(a) != in_root_dir(b)) {
439+
return in_root_dir(a) - in_root_dir(b)
440+
} else if (a.name < b.name) {
441+
return -1
442+
} else if (a.name > b.name) {
443+
return 1
444+
else {
445+
return 0
446+
}
447+
})[0]
448+
this.#select(top_file);
433449
}
434450

435451
this.#files = files;

0 commit comments

Comments
 (0)
0