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,
// What the tab menu's share entry needs, read at call time.
getShareTarget: () => slotApiRef.current?.getShareTarget() ?? null,
openFileManager: () => {
if (webSocketRef.current?.readyState === WebSocket.OPEN) {
webSocketRef.current.send(JSON.stringify({ type: "get_cwd" }));
} else {
onOpenFileManager?.("/");
}
},
openFileManager: () => openFilesAtCwd(),
}),
[isConnected, terminal],
);
@@ -1502,6 +1496,14 @@ const TerminalInner = forwardRef<TerminalHandle, SSHTerminalProps>(
return getClientPreference("copyOnSelect") === "true";
}
function openFilesAtCwd() {
if (webSocketRef.current?.readyState === WebSocket.OPEN) {
webSocketRef.current.send(JSON.stringify({ type: "get_cwd" }));
} else {
onOpenFileManager?.("/");
}
}
function attemptReconnection() {
if (
isUnmountingRef.current ||
@@ -3713,6 +3715,7 @@ const TerminalInner = forwardRef<TerminalHandle, SSHTerminalProps>(
onPasteImage={() => void handleClipboardImage()}
isFocused={isFocusedPane}
slotApi={slotApi}
onOpenFiles={onOpenFileManager ? openFilesAtCwd : undefined}
/>
)}
@@ -90,6 +90,8 @@ interface TerminalToolbarProps {
onUploadImage: (file: File) => void | Promise<void>;
onPasteImage: () => void | Promise<void>;
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. */
actionsEnabled?: boolean;
/** Handed to contributed actions when they are invoked. */
@@ -108,6 +110,7 @@ export const TerminalToolbar: React.FC<TerminalToolbarProps> = ({
isFocused,
actionsEnabled = true,
slotApi,
onOpenFiles,
}) => {
const { t } = useTranslation();
// Drives both the measurement copy and the separator, so the toolbar sizes
@@ -140,7 +143,9 @@ export const TerminalToolbar: React.FC<TerminalToolbarProps> = ({
}, [hostActions, host]);
const openHostLink = (action: (typeof hostLinks)[number]) => {
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);
};
const settings = useMemo(() => readToolbarSettings(host), [host]);
@@ -149,6 +149,28 @@ afterEach(() => {
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", () => {
it("enters below 110 percent and restores at 115 percent", () => {
expect(getResponsiveToolbarDensity("labeled", "labeled", 1099, 1000)).toBe(