Skip to content

Commit ad2e4a9

Browse files
authored
Merge pull request #13 from devklick/dev
Dev
2 parents ffdca8e + 4302f5a commit ad2e4a9

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

Diff for: src/hooks/useBindKeyToAction.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function useBindKeyToAction({ keys, action }: UseBindKeyToActionProps) {
1717
window?.addEventListener("keydown", handler);
1818

1919
return () => {
20-
window?.addEventListener("keydown", handler);
20+
window?.removeEventListener("keydown", handler);
2121
};
2222
}, [action, keys]);
2323
}

Diff for: src/stores/localFS.ts

+26-7
Original file line numberDiff line numberDiff line change
@@ -276,19 +276,38 @@ export const useLocalFS = create<LocalFSState>()(
276276
) => {
277277
const oldName = fsObject.name;
278278
const oldPath = fsObject.path;
279-
280-
// Update the FSObject to have the new name
281-
fsObject.name = newName;
282-
fsObject.path = [
279+
const newPath = [
283280
...fsObject.path.split(pathSeparator).slice(0, -1),
284281
newName,
285282
].join(pathSeparator);
286283

287-
// Delete the old one from the parent
288-
delete parentDirectory.contents[oldName];
289-
290284
// Update the parent so it knows about the rename
291285
parentDirectory.contents[newName] = fsObject;
286+
delete parentDirectory.contents[oldName];
287+
288+
// Update the FSObject to have the new name
289+
fsObject.name = newName;
290+
291+
// The path is also stored on each of the children,
292+
// so we need to update the renamed dir on them to.
293+
// This isnt ideal, as we'll going to have to loop over
294+
// them all recursively. A better way to do this might be to not
295+
// store the path on each FSObject and instead store a reference to
296+
// the parent FSDirectory, but this would very tricky to persist
297+
function updatePathRecursive(fsObject: FSObject) {
298+
console.log("Updating", fsObject.path);
299+
const regex = new RegExp(`^${oldPath}`);
300+
fsObject.path = fsObject.path.replace(regex, newPath);
301+
console.log("Updated to", fsObject.path);
302+
303+
if (!isFSDirectory(fsObject)) return;
304+
305+
for (const child of Object.values<FSObject>(fsObject.contents)) {
306+
updatePathRecursive(child);
307+
}
308+
}
309+
310+
updatePathRecursive(fsObject);
292311

293312
// If the FSObject is in the favorites, update that too.
294313
const favorites = get().favorites;

0 commit comments

Comments
 (0)