Skip to content

Commit a1b8f8d

Browse files
committed
fix: harden workspace pane lifecycle
1 parent fdbb526 commit a1b8f8d

8 files changed

Lines changed: 69 additions & 2 deletions

File tree

‎apps/server/src/keybindings.test.ts‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,36 @@ it.layer(NodeServices.layer)("keybindings", (it) => {
307307
}).pipe(Effect.provide(makeKeybindingsLayer())),
308308
);
309309

310+
it.effect("preserves the former preview default when its destination is customized", () =>
311+
Effect.gen(function* () {
312+
const { keybindingsConfigPath } = yield* ServerConfig.ServerConfig;
313+
yield* writeKeybindingsConfig(keybindingsConfigPath, [
314+
{ key: "mod+shift+j", command: "preview.toggle" },
315+
{ key: "mod+shift+v", command: "script.custom-action.run" },
316+
]);
317+
318+
const keybindings = yield* Keybindings.Keybindings;
319+
yield* keybindings.syncDefaultKeybindingsOnStartup;
320+
321+
const persisted = yield* readKeybindingsConfig(keybindingsConfigPath);
322+
assert.isTrue(
323+
persisted.some(
324+
(entry) => entry.command === "preview.toggle" && entry.key === "mod+shift+j",
325+
),
326+
);
327+
assert.isTrue(
328+
persisted.some(
329+
(entry) => entry.command === "script.custom-action.run" && entry.key === "mod+shift+v",
330+
),
331+
);
332+
assert.isFalse(
333+
persisted.some(
334+
(entry) => entry.command === "preview.toggle" && entry.key === "mod+shift+v",
335+
),
336+
);
337+
}).pipe(Effect.provide(makeKeybindingsLayer())),
338+
);
339+
310340
it.effect("skips conflicting default keybindings on startup and logs a detailed warning", () => {
311341
const messages: string[] = [];
312342
const logger = Logger.make(({ message }) => {

‎apps/server/src/keybindings.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,15 @@ function migrateChangedDefaultKeybindings(config: readonly KeybindingRule[]): {
119119
readonly changed: boolean;
120120
} {
121121
let changed = false;
122+
const destinationOccupied = config.some(
123+
(rule) =>
124+
!isSameKeybindingRule(rule, CURRENT_PREVIEW_TOGGLE_DEFAULT) &&
125+
hasSameShortcutContext(rule, CURRENT_PREVIEW_TOGGLE_DEFAULT),
126+
);
122127

123128
const keybindings = config.map((rule) => {
124129
if (!isSameKeybindingRule(rule, LEGACY_PREVIEW_TOGGLE_DEFAULT)) return rule;
130+
if (destinationOccupied) return rule;
125131
changed = true;
126132
return CURRENT_PREVIEW_TOGGLE_DEFAULT;
127133
});

‎apps/web/src/components/SplitPaneGrid.tsx‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
type ReactNode,
1616
type RefObject,
1717
useCallback,
18+
useEffect,
1819
useLayoutEffect,
1920
useMemo,
2021
useRef,
@@ -656,6 +657,15 @@ function PaneSplitHandle(props: {
656657
dragStateRef.current = null;
657658
}, []);
658659

660+
useEffect(
661+
() => () => {
662+
const dragState = dragStateRef.current;
663+
664+
if (dragState) releasePointer(dragState.pointerId);
665+
},
666+
[releasePointer],
667+
);
668+
659669
const handlePointerDown = useCallback(
660670
(event: PointerEvent<HTMLDivElement>) => {
661671
if (event.button !== 0) return;

‎apps/web/src/components/ThreadTerminalDrawer.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ export function TerminalViewport({
380380
// cannot be mistaken for the active flow.
381381
const openSelectionMenuRequestIdRef = useRef<number | null>(null);
382382
const keybindingsRef = useRef(keybindings);
383+
const workspaceShortcutsEnabledRef = useRef(workspaceShortcutsEnabled);
383384
const runtimeEnvKey = useMemo(() => runtimeEnvSignature(runtimeEnv), [runtimeEnv]);
384385
const handleSessionExited = useEffectEvent(() => {
385386
onSessionExited();
@@ -468,6 +469,10 @@ export function TerminalViewport({
468469
keybindingsRef.current = keybindings;
469470
}, [keybindings]);
470471

472+
useEffect(() => {
473+
workspaceShortcutsEnabledRef.current = workspaceShortcutsEnabled;
474+
}, [workspaceShortcutsEnabled]);
475+
471476
useLayoutEffect(() => {
472477
visibleRef.current = visible;
473478
terminalRef.current?.setVisible(visible);
@@ -757,7 +762,7 @@ export function TerminalViewport({
757762
isTerminalSplitVerticalShortcut(event, currentKeybindings, options) ||
758763
isTerminalNewShortcut(event, currentKeybindings, options) ||
759764
isDiffToggleShortcut(event, currentKeybindings, options) ||
760-
(workspaceShortcutsEnabled &&
765+
(workspaceShortcutsEnabledRef.current &&
761766
isWorkspaceShortcutReleasedFromTerminal(event, currentKeybindings, options))
762767
) {
763768
return false;

‎apps/web/src/hooks/useThreadActions.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
readThreadShells,
3535
} from "../state/entities";
3636
import { useTerminalUiStateStore } from "../terminalUiStateStore";
37+
import { useThreadWorkspaceLayoutStore } from "../threadWorkspaceLayoutStore";
3738
import { useUiStateStore } from "../uiStateStore";
3839
import { buildThreadRouteParams, resolveThreadRouteRef } from "../threadRoutes";
3940
import { formatWorktreePathForDisplay, getOrphanedWorktreePathForThread } from "../worktreeCleanup";
@@ -321,6 +322,7 @@ export function useThreadActions() {
321322
});
322323
if (result._tag === "Success") {
323324
refreshArchivedThreadsForEnvironment(target.environmentId);
325+
useThreadWorkspaceLayoutStore.getState().removeThread(target);
324326
}
325327
return result;
326328
}
@@ -412,6 +414,7 @@ export function useThreadActions() {
412414
threadRef,
413415
);
414416
clearTerminalUiState(threadRef);
417+
useThreadWorkspaceLayoutStore.getState().removeThread(threadRef);
415418

416419
if (shouldNavigateToFallback) {
417420
const fallbackThread = fallbackThreadId

‎apps/web/src/rightPanelStore.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,13 +848,18 @@ describe("rightPanelStore", () => {
848848
it("toggle hides the panel without discarding the active surface", () => {
849849
useRightPanelStore.getState().toggle(refA, "diff");
850850
expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBe("diff");
851+
splitSurfaceIntoSoleTabPane("diff");
851852
useRightPanelStore.getState().toggle(refA, "diff");
852853
expect(selectActiveRightPanel(useRightPanelStore.getState().byThreadKey, refA)).toBeNull();
853854
expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toEqual({
854855
isOpen: false,
855856
activeSurfaceId: "diff",
856857
surfaces: [{ id: "diff", kind: "diff" }],
857858
});
859+
expect(
860+
selectThreadWorkspaceLayout(useThreadWorkspaceLayoutStore.getState().byThreadKey, refA)
861+
.rightSidebarVisibility,
862+
).toBe("closed");
858863
});
859864

860865
it("toggle to a different kind switches active", () => {

‎apps/web/src/rightPanelStore.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,14 @@ export const useRightPanelStore = create<RightPanelStoreState>()(
956956
return upsertSurface(current, singletonSurface(kind));
957957
}),
958958
);
959+
const panel = selectThreadRightPanelState(get().byThreadKey, ref);
960+
if (!panel.isOpen) {
961+
transitionThreadWorkspaceLayout(ref, {
962+
_tag: "SetRightSidebarVisibility",
963+
visibility: "closed",
964+
});
965+
return;
966+
}
959967
revealThreadWorkspaceSurface(ref);
960968
},
961969
removeThread: (ref) =>

‎docs/user/devices.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Each device opens in its own tab. Use **+ → Device** to open another, and
1919
double-click a tab name or choose **Rename** from its context menu to rename it.
2020
Only the visible tab streams video; switching tabs keeps both devices running.
2121
Choose **Float device over chat** in the toolbar to keep watching and tapping the
22-
device in a small window while the right panel shows something else; drag the
22+
device in a small window while the workspace pane shows something else; drag the
2323
window by its handle, resize it from any edge, and use **Open in right panel**
2424
to bring it back.
2525
Turn off the device hub in **Settings → Integrations → Devices** to stop the

0 commit comments

Comments
 (0)