Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
151 lines
4.6 KiB
TypeScript
151 lines
4.6 KiB
TypeScript
import type React from 'react';
|
|
|
|
export type PaneMagnificationState = 'unavailable' | 'focusable' | 'focused';
|
|
|
|
export type PaneMagnificationController = {
|
|
getState: () => PaneMagnificationState;
|
|
toggle: () => boolean;
|
|
focus: () => boolean;
|
|
restore: () => boolean;
|
|
};
|
|
|
|
export type PaneMagnificationTarget =
|
|
| { kind: 'terminal'; sessionId: string }
|
|
| { kind: 'side-panel'; paneId: string; tool: string };
|
|
|
|
export function isPaneMagnificationSelectionValid(
|
|
selection: { tabId: string; target: PaneMagnificationTarget },
|
|
terminalPanes: Array<{ tabId: string; sessionId: string }>,
|
|
sidePanelPanes: Array<{ tabId: string; paneId: string }>,
|
|
): boolean {
|
|
return selection.target.kind === 'terminal'
|
|
? terminalPanes.some((pane) => (
|
|
pane.tabId === selection.tabId && pane.sessionId === selection.target.sessionId
|
|
))
|
|
: sidePanelPanes.some((pane) => (
|
|
pane.tabId === selection.tabId && pane.paneId === selection.target.paneId
|
|
));
|
|
}
|
|
|
|
export function resolvePaneMagnificationCandidate({
|
|
tabId,
|
|
terminalSessionIds,
|
|
focusedSessionId,
|
|
sidePanelPanes,
|
|
lastTarget,
|
|
current,
|
|
}: {
|
|
tabId: string;
|
|
terminalSessionIds: string[];
|
|
focusedSessionId?: string | null;
|
|
sidePanelPanes: Array<{ id: string; tool: string }>;
|
|
lastTarget?: PaneMagnificationTarget;
|
|
current: { tabId: string; target: PaneMagnificationTarget } | null;
|
|
}): { target: PaneMagnificationTarget; focused: boolean } | null {
|
|
if (terminalSessionIds.length + sidePanelPanes.length < 2) return null;
|
|
const targetIsValid = (target: PaneMagnificationTarget) => (
|
|
target.kind === 'terminal'
|
|
? terminalSessionIds.includes(target.sessionId)
|
|
: sidePanelPanes.some((pane) => pane.id === target.paneId)
|
|
);
|
|
if (current?.tabId === tabId && targetIsValid(current.target)) {
|
|
return { target: current.target, focused: true };
|
|
}
|
|
if (lastTarget && targetIsValid(lastTarget)) {
|
|
if (lastTarget.kind === 'side-panel') {
|
|
return { target: lastTarget, focused: false };
|
|
}
|
|
if (focusedSessionId && terminalSessionIds.includes(focusedSessionId)) {
|
|
return {
|
|
target: { kind: 'terminal', sessionId: focusedSessionId },
|
|
focused: false,
|
|
};
|
|
}
|
|
return { target: lastTarget, focused: false };
|
|
}
|
|
const terminalSessionId = focusedSessionId && terminalSessionIds.includes(focusedSessionId)
|
|
? focusedSessionId
|
|
: terminalSessionIds[0];
|
|
if (terminalSessionId) {
|
|
return { target: { kind: 'terminal', sessionId: terminalSessionId }, focused: false };
|
|
}
|
|
const pane = sidePanelPanes[0];
|
|
return pane
|
|
? { target: { kind: 'side-panel', paneId: pane.id, tool: pane.tool }, focused: false }
|
|
: null;
|
|
}
|
|
|
|
export function getAvailablePaneMagnificationController(
|
|
controllers: Array<PaneMagnificationController | null | undefined>,
|
|
): PaneMagnificationController | null {
|
|
return controllers.find((controller) => (
|
|
controller && controller.getState() !== 'unavailable'
|
|
)) ?? null;
|
|
}
|
|
|
|
export function getPaneMagnificationShortcutLabel(
|
|
keyBindings: Array<{ id: string; mac: string; pc: string }> | undefined,
|
|
hotkeyScheme: 'mac' | 'pc' | 'disabled' | undefined,
|
|
): string {
|
|
if (!keyBindings || !hotkeyScheme || hotkeyScheme === 'disabled') return '';
|
|
const binding = keyBindings.find((entry) => entry.id === 'toggle-pane-zoom');
|
|
return (hotkeyScheme === 'mac' ? binding?.mac : binding?.pc)?.replace(/ \+ /g, '+') ?? '';
|
|
}
|
|
|
|
export function resolvePaneMagnificationStyle(
|
|
original: React.CSSProperties,
|
|
magnified: boolean,
|
|
surfaceBounds?: { left: number; top: number; width: number; height: number } | null,
|
|
): React.CSSProperties {
|
|
if (!magnified) return original;
|
|
if (surfaceBounds) {
|
|
return {
|
|
position: 'fixed',
|
|
left: `${surfaceBounds.left + 12}px`,
|
|
top: `${surfaceBounds.top + 12}px`,
|
|
width: `${Math.max(0, surfaceBounds.width - 24)}px`,
|
|
height: `${Math.max(0, surfaceBounds.height - 24)}px`,
|
|
zIndex: 50,
|
|
};
|
|
}
|
|
return {
|
|
left: '12px',
|
|
top: '12px',
|
|
width: 'calc(100% - 24px)',
|
|
height: 'calc(100% - 24px)',
|
|
zIndex: 50,
|
|
};
|
|
}
|
|
|
|
export function resolveTwoPaneMagnificationStyle(
|
|
side: 'left' | 'right',
|
|
wide: boolean,
|
|
magnified: boolean,
|
|
): React.CSSProperties {
|
|
if (magnified) {
|
|
return {
|
|
left: '12px',
|
|
top: '12px',
|
|
width: 'calc(100% - 24px)',
|
|
height: 'calc(100% - 24px)',
|
|
zIndex: 50,
|
|
};
|
|
}
|
|
if (wide) {
|
|
return {
|
|
left: side === 'left' ? '0%' : '50%',
|
|
top: '0%',
|
|
width: '50%',
|
|
height: '100%',
|
|
zIndex: 10,
|
|
};
|
|
}
|
|
return {
|
|
left: '0%',
|
|
top: side === 'left' ? '0%' : '50%',
|
|
width: '100%',
|
|
height: '50%',
|
|
zIndex: 10,
|
|
};
|
|
}
|