2code icon indicating copy to clipboard operation
2code copied to clipboard

Files panel jumps to the space's starting folder when a file tab is focused

Open cahva opened this issue 2 weeks ago • 0 comments

Opening a file from the Files panel opens it in a new tab, and the tree then switches to the folder the space was created in, often ~. I expected the tree to stay on the folder I opened the file from.

A file tab is a mod pane with no cwd, so location() in parts/files.js falls back to space.folder. A possible fix: openFile in lib/editor.js stores root in 2code.editors, and location() checks it before the fallback. It falls back to place(space) from lib/git.js for tabs opened before the change, the same fallback here() uses.

--- a/mods/2code/lib/editor.js
+++ b/mods/2code/lib/editor.js
-    if (tab) { setShared("2code.editors", { ...editorTabs(), [tab.id]: { path, on } }); return; }
+    if (tab) { setShared("2code.editors", { ...editorTabs(), [tab.id]: { path, on, root } }); return; }
--- a/mods/2code/parts/files.js
+++ b/mods/2code/parts/files.js
-import { READ } from "../lib/git.js";
+import { READ, place } from "../lib/git.js";
-import { openFile } from "../lib/editor.js";
+import { openFile, editorOf } from "../lib/editor.js";
-  return { cwd: pane?.cwd || f?.cwd || space?.folder, on, space: space?.id };
+  return { cwd: pane?.cwd || f?.cwd || editorOf(f?.tab)?.root || place(space) || space?.folder, on, space: space?.id };

Tested on Linux, herdr-app 0.1.16, 2code at 3be336e.

cahva avatar Nov 17 '26 06:11 cahva