fix: toolbar files button opens at the shell directory again

This commit is contained in:
LukeGus committed 2026-09-30 14:42:29 -05:00
1 parent 20f19ff13b
commit 9ce63d65d3
3 files changed
+38 -8

No files matched your search

@@ -1487,13 +1487,7 @@ const TerminalInner = forwardRef<TerminalHandle, SSHTerminalProps>(
terminal?.modes?.applicationCursorKeysMode ?? false, terminal?.modes?.applicationCursorKeysMode ?? false,
// What the tab menu's share entry needs, read at call time. // What the tab menu's share entry needs, read at call time.
getShareTarget: () => slotApiRef.current?.getShareTarget() ?? null, getShareTarget: () => slotApiRef.current?.getShareTarget() ?? null,
openFileManager: () => { openFileManager: () => openFilesAtCwd(),
if (webSocketRef.current?.readyState === WebSocket.OPEN) {
webSocketRef.current.send(JSON.stringify({ type: "get_cwd" }));
} else {
onOpenFileManager?.("/");
}
},
}), }),
[isConnected, terminal], [isConnected, terminal],
); );
@@ -1502,6 +1496,14 @@ const TerminalInner = forwardRef<TerminalHandle, SSHTerminalProps>(
return getClientPreference("copyOnSelect") === "true"; return getClientPreference("copyOnSelect") === "true";
} }
function openFilesAtCwd() {
if (webSocketRef.current?.readyState === WebSocket.OPEN) {
webSocketRef.current.send(JSON.stringify({ type: "get_cwd" }));
} else {
onOpenFileManager?.("/");
}
}
function attemptReconnection() { function attemptReconnection() {
if ( if (
isUnmountingRef.current || isUnmountingRef.current ||
@@ -3713,6 +3715,7 @@ const TerminalInner = forwardRef<TerminalHandle, SSHTerminalProps>(
onPasteImage={() => void handleClipboardImage()} onPasteImage={() => void handleClipboardImage()}
isFocused={isFocusedPane} isFocused={isFocusedPane}
slotApi={slotApi} slotApi={slotApi}
onOpenFiles={onOpenFileManager ? openFilesAtCwd : undefined}
/> />
)} )}
@@ -90,6 +90,8 @@ interface TerminalToolbarProps {
onUploadImage: (file: File) => void | Promise<void>; onUploadImage: (file: File) => void | Promise<void>;
onPasteImage: () => void | Promise<void>; onPasteImage: () => void | Promise<void>;
isFocused: boolean; isFocused: boolean;
/** Opens the file manager at the shell's working directory. */
onOpenFiles?: () => void;
/** Hides every contributed action, e.g. while the toolbar is measuring. */ /** Hides every contributed action, e.g. while the toolbar is measuring. */
actionsEnabled?: boolean; actionsEnabled?: boolean;
/** Handed to contributed actions when they are invoked. */ /** Handed to contributed actions when they are invoked. */
@@ -108,6 +110,7 @@ export const TerminalToolbar: React.FC<TerminalToolbarProps> = ({
isFocused, isFocused,
actionsEnabled = true, actionsEnabled = true,
slotApi, slotApi,
onOpenFiles,
}) => { }) => {
const { t } = useTranslation(); const { t } = useTranslation();
// Drives both the measurement copy and the separator, so the toolbar sizes // Drives both the measurement copy and the separator, so the toolbar sizes
@@ -140,7 +143,9 @@ export const TerminalToolbar: React.FC<TerminalToolbarProps> = ({
}, [hostActions, host]); }, [hostActions, host]);
const openHostLink = (action: (typeof hostLinks)[number]) => { const openHostLink = (action: (typeof hostLinks)[number]) => {
const record = host as unknown as PluginHostRecord; const record = host as unknown as PluginHostRecord;
if (action.run) action.run(record, tabs as unknown as ShellApi); // The file manager opens where the shell is, as in 2.8.
if (action.tabType === "files" && onOpenFiles) onOpenFiles();
else if (action.run) action.run(record, tabs as unknown as ShellApi);
else if (action.tabType) tabs.openTab(record, action.tabType); else if (action.tabType) tabs.openTab(record, action.tabType);
}; };
const settings = useMemo(() => readToolbarSettings(host), [host]); const settings = useMemo(() => readToolbarSettings(host), [host]);
@@ -149,6 +149,28 @@ afterEach(() => {
vi.unstubAllGlobals(); vi.unstubAllGlobals();
}); });
describe("toolbar host links", () => {
it("opens the file manager at the shell directory instead of a plain tab", () => {
const run = vi.fn();
slots.hostActions = [
{
id: "files",
kind: "open",
tabType: "files",
titleKey: "Files",
icon: () => null,
when: () => true,
run,
},
];
const onOpenFiles = vi.fn();
renderToolbar({ onOpenFiles });
fireEvent.click(screen.getAllByRole("button", { name: "Files" })[0]);
expect(onOpenFiles).toHaveBeenCalledOnce();
expect(run).not.toHaveBeenCalled();
});
});
describe("responsive toolbar density", () => { describe("responsive toolbar density", () => {
it("enters below 110 percent and restores at 115 percent", () => { it("enters below 110 percent and restores at 115 percent", () => {
expect(getResponsiveToolbarDensity("labeled", "labeled", 1099, 1000)).toBe( expect(getResponsiveToolbarDensity("labeled", "labeled", 1099, 1000)).toBe(