Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions src/kicanvas/services/vfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -352,20 +352,29 @@ export class DragAndDropFileSystem extends LocalFileSystemBase {
}

private static lcp(str: string[]): string {
const beg = str[0] ?? "";
return str.reduce((common, path) => {
let i = 0;
if (str.length === 0) {
return "";
}

while (
i < common.length &&
i < path.length &&
common[i] === path[i]
) {
// split dirname only
const str_arr = str.map((s) =>
s.split("/").filter(Boolean).slice(0, -1),
);

const fst = str_arr[0]!;
let p_len = fst.length;
for (const s of str_arr.slice(1)) {
let i = 0;
while (i < p_len && i < s.length && fst[i] === s[i]) {
i += 1;
}
p_len = i;
if (p_len === 0) {
break;
}
}

return common.slice(0, i);
}, beg);
return fst.slice(0, p_len).join("/");
}

private static async load(entry: FileSystemFileEntry): Promise<File> {
Expand Down
Loading