Compare commits

...
4 changed files with 206 additions and 11 deletions

No files matched your search

@@ -52,7 +52,9 @@ import type { ResolvedAppearance, TerminalAppearanceHostScope } from '../../doma
import type { TerminalSidePanelAutoOpenTab } from '../../domain/terminalSidePanelAutoOpen';
import type { SidePanelTool } from '../../domain/sidePanelLayout';
import {
PANE_MAGNIFICATION_DURATION_MS,
resolveMagnifiedChromeBorderWidth,
resolvePaneMagnificationLayoutGeometry,
resolvePaneMagnificationStyle,
type PaneMagnificationController,
type PaneMagnificationTarget,
@@ -1454,22 +1456,51 @@ const TerminalPane: React.FC<TerminalPaneProps> = memo(({
top: number;
width: number;
height: number;
layoutOrigin: { left: number; top: number; width: number; height: number };
} | null>(null);
useLayoutEffect(() => {
if (!isMagnified) {
setMagnifiedSurfaceBounds(null);
return undefined;
if (!isVisible) {
setMagnifiedSurfaceBounds(null);
return undefined;
}
// Keep the geometry transition and stacking level through restore.
const timerId = window.setTimeout(
() => setMagnifiedSurfaceBounds(null),
PANE_MAGNIFICATION_DURATION_MS + 50,
);
return () => window.clearTimeout(timerId);
}
const pane = paneElementRef.current;
const surface = pane?.closest<HTMLElement>('[data-section="terminal-workspace"]');
if (!surface) return undefined;
// The direct parent is the relative split layout container, even while
// the pane is fixed (offsetParent would be null during a quick re-zoom).
const layoutParent = pane?.parentElement;
if (!surface || !layoutParent) return undefined;
const update = () => {
const bounds = surface.getBoundingClientRect();
const origin = layoutParent.getBoundingClientRect();
if (pane && pane.style.position !== 'fixed') {
const geometry = {
left: pane.style.left,
top: pane.style.top,
width: pane.style.width,
height: pane.style.height,
};
if (Object.values(geometry).some((value) => value.endsWith('%'))) {
// Commit parent-resolved pixels while still absolute. Flush layout
// before switching to fixed so the transition starts from these px,
// rather than re-resolving the old percentages against the viewport.
Object.assign(pane.style, resolvePaneMagnificationLayoutGeometry(geometry, origin));
pane.getBoundingClientRect();
}
}
setMagnifiedSurfaceBounds({
left: bounds.left,
top: bounds.top,
width: bounds.width,
height: bounds.height,
layoutOrigin: { left: origin.left, top: origin.top, width: origin.width, height: origin.height },
});
};
update();
@@ -1477,13 +1508,14 @@ const TerminalPane: React.FC<TerminalPaneProps> = memo(({
const observer = new ResizeObserver(update);
observer.observe(surface);
return () => observer.disconnect();
}, [isMagnified]);
}, [isMagnified, isVisible]);
const magnifiedDevicePixelRatio = typeof window === 'undefined' ? 1 : (window.devicePixelRatio || 1);
const style: React.CSSProperties = resolvePaneMagnificationStyle(
layoutStyle,
isMagnified && !!magnifiedSurfaceBounds,
magnifiedSurfaceBounds,
magnifiedDevicePixelRatio,
magnifiedSurfaceBounds?.layoutOrigin,
);
useLayoutEffect(() => {
@@ -1641,7 +1673,7 @@ const TerminalPane: React.FC<TerminalPaneProps> = memo(({
"absolute bg-background",
inActiveWorkspace && "workspace-pane",
isVisible && "z-10",
isMagnified && magnifiedSurfaceBounds && "overflow-hidden rounded-md border shadow-2xl animate-in fade-in zoom-in-95 duration-150",
isMagnified && magnifiedSurfaceBounds && "overflow-hidden rounded-md border shadow-2xl",
)}
style={{
...style,
@@ -13,7 +13,7 @@ test("magnified terminal panes use the resolved terminal accent for border chrom
const source = readFileSync(new URL("./TerminalLayerSupport.tsx", import.meta.url), "utf8");
const paneSource = source.slice(source.indexOf('data-section="terminal-split-pane"'), source.indexOf("<Terminal\n"));
assert.match(paneSource, /isMagnified && magnifiedSurfaceBounds && "overflow-hidden rounded-md border shadow-2xl /);
assert.match(paneSource, /isMagnified && magnifiedSurfaceBounds && "overflow-hidden rounded-md border shadow-2xl"/);
assert.match(paneSource, /borderColor: isMagnified && magnifiedSurfaceBounds \? sessionAppearanceTheme\.colors\.cursor : undefined/);
assert.match(paneSource, /borderWidth: isMagnified && magnifiedSurfaceBounds/);
assert.match(paneSource, /resolveMagnifiedChromeBorderWidth\(magnifiedDevicePixelRatio\)/);
@@ -21,10 +21,19 @@ test("magnified terminal panes use the resolved terminal accent for border chrom
test("magnified terminal panes snap overlay bounds to the device-pixel grid", () => {
const source = readFileSync(new URL("./TerminalLayerSupport.tsx", import.meta.url), "utf8");
assert.match(source, /resolvePaneMagnificationStyle\(\s*layoutStyle,\s*isMagnified && !!magnifiedSurfaceBounds,\s*magnifiedSurfaceBounds,\s*magnifiedDevicePixelRatio,\s*\)/);
assert.match(source, /resolvePaneMagnificationStyle\(\s*layoutStyle,\s*isMagnified && !!magnifiedSurfaceBounds,\s*magnifiedSurfaceBounds,\s*magnifiedDevicePixelRatio,\s*magnifiedSurfaceBounds\?\.layoutOrigin,\s*\)/);
assert.match(source, /layoutOrigin: \{ left: origin\.left, top: origin\.top, width: origin\.width, height: origin\.height \}/);
assert.match(source, /const magnifiedDevicePixelRatio = typeof window === 'undefined' \? 1 : \(window\.devicePixelRatio \|\| 1\)/);
});
test("percentage zoom entry flushes pixel geometry before applying fixed bounds", () => {
const source = readFileSync(new URL("./TerminalLayerSupport.tsx", import.meta.url), "utf8");
assert.match(source, /pane && pane\.style\.position !== 'fixed'/);
assert.match(source, /Object\.values\(geometry\)\.some\(\(value\) => value\.endsWith\('%'\)\)/);
assert.match(source, /Object\.assign\(pane\.style, resolvePaneMagnificationLayoutGeometry\(geometry, origin\)\);\s+pane\.getBoundingClientRect\(\);\s+\}\s+\}\s+setMagnifiedSurfaceBounds\(/);
});
test("terminal keyboard focus updates the pane selected for magnification", () => {
const source = readFileSync(new URL("./TerminalLayerSupport.tsx", import.meta.url), "utf8");
+104
View File
@@ -5,7 +5,9 @@ import {
getAvailablePaneMagnificationController,
getPaneMagnificationShortcutLabel,
isPaneMagnificationSelectionValid,
PANE_MAGNIFICATION_DURATION_MS,
resolvePaneMagnificationCandidate,
resolvePaneMagnificationLayoutGeometry,
resolvePaneMagnificationStyle,
resolveMagnifiedChromeBorderWidth,
resolveTwoPaneMagnificationStyle,
@@ -13,6 +15,12 @@ import {
type PaneMagnificationController,
} from './paneMagnification.ts';
const geometryTransition = {
transitionProperty: 'left, top, width, height',
transitionDuration: '200ms',
transitionTimingFunction: 'ease-out',
};
test('selects the first controller that can magnify the active surface', () => {
const unavailable: PaneMagnificationController = {
getState: () => 'unavailable',
@@ -83,6 +91,7 @@ test('magnification overlays the original layout without changing its rect', ()
width: 1400,
height: 900,
}), {
...geometryTransition,
position: 'fixed',
left: '132px',
top: '92px',
@@ -110,6 +119,7 @@ test('magnified surface bounds snap to the device-pixel grid after the 12px inse
width: 1400,
height: 900,
}, 1), {
...geometryTransition,
position: 'fixed',
left: '132px',
top: '92px',
@@ -127,6 +137,7 @@ test('magnified surface bounds snap to the device-pixel grid after the 12px inse
height: 900,
}, 2);
assert.deepEqual(snapped, {
...geometryTransition,
position: 'fixed',
left: '132.5px',
top: '92.5px',
@@ -139,6 +150,99 @@ test('magnified surface bounds snap to the device-pixel grid after the 12px inse
assert.deepEqual(rect, { left: 10, top: 20, width: 100, height: 60 });
});
test('switching to fixed positioning preserves the split origin below the tabs', () => {
const original = { left: '300px', top: '0px', width: '300px', height: '400px' };
const surface = { left: 100.4, top: 80.4, width: 1000, height: 800 };
// A sidebar can offset the split containing block within the workspace.
const origin = { left: 280.4, top: 80.4 };
const magnified = resolvePaneMagnificationStyle(original, true, surface, 2, origin);
const px = (value: unknown) => parseFloat(String(value));
// The initial fixed frame uses the old local offsets. Non-transitioning
// margins keep that frame at the same viewport position as the split pane.
assert.equal(px(original.top) + px(magnified.marginTop), origin.top);
assert.equal(px(original.left) + px(magnified.marginLeft), origin.left + 300);
// The final rect is the device-snapped workspace inset, not a viewport inset
// or an inset from the smaller split containing block.
assert.equal(px(magnified.top) + px(magnified.marginTop), 92.5);
assert.equal(px(magnified.left) + px(magnified.marginLeft), 112.5);
assert.equal(px(magnified.width), 976);
assert.equal(px(magnified.height), 776);
assert.deepEqual(original, { left: '300px', top: '0px', width: '300px', height: '400px' });
});
test('restore retains the same geometry transition and overlay stacking until bounds clear', () => {
const original = { left: '0px', top: '400px', width: '600px', height: '400px' };
const surface = { left: 0, top: 80, width: 1200, height: 800 };
const origin = { left: 0, top: 80, width: 1200, height: 800 };
const magnified = resolvePaneMagnificationStyle(original, true, surface, 1, origin);
const restoring = resolvePaneMagnificationStyle(original, false, surface, 1, origin);
for (const property of ['transitionProperty', 'transitionDuration', 'transitionTimingFunction'] as const) {
assert.equal(restoring[property], magnified[property]);
assert.equal(restoring[property], geometryTransition[property]);
}
assert.equal(PANE_MAGNIFICATION_DURATION_MS, 200);
assert.equal(restoring.zIndex, 50);
assert.equal(restoring.position, 'fixed');
assert.equal(restoring.marginTop, '80px');
for (const property of ['left', 'top', 'width', 'height'] as const) {
assert.equal(restoring[property], original[property]);
}
assert.equal(resolvePaneMagnificationStyle(original, false, null), original);
});
test('standalone zoom entry commits parent-resolved pixels before switching to fixed', () => {
const original = { left: 0, top: 0, width: '100%', height: '100%' };
const surface = { left: 220, top: 36, width: 1180, height: 864 };
const origin = { left: 640, top: 36, width: 760, height: 864 };
// Commit and flush this geometry while absolute, then apply the fixed target.
// The CSS transition's starting lengths must already be px at that switch.
const entry = resolvePaneMagnificationLayoutGeometry(original, origin);
assert.deepEqual(entry, { left: '0px', top: '0px', width: '760px', height: '864px' });
assert.equal(entry.position, undefined);
assert.equal(entry.transitionDuration, undefined);
const target = resolvePaneMagnificationStyle(original, true, surface, 1, origin);
assert.deepEqual(target, {
...geometryTransition,
position: 'fixed',
marginLeft: '640px',
marginTop: '36px',
left: '-408px',
top: '12px',
width: '1156px',
height: '840px',
zIndex: 50,
});
assert.deepEqual(original, { left: 0, top: 0, width: '100%', height: '100%' });
});
test('standalone terminal restore resolves percentage geometry against its layout parent', () => {
const original = { left: 0, top: 0, width: '100%', height: '100%' };
const surface = { left: 100, top: 80, width: 1200, height: 800 };
const origin = { left: 300, top: 100, width: 1000, height: 760 };
const magnified = resolvePaneMagnificationStyle(original, true, surface, 1, origin);
const restoring = resolvePaneMagnificationStyle(original, false, surface, 1, origin);
assert.deepEqual(restoring, {
...geometryTransition,
position: 'fixed',
zIndex: 50,
marginLeft: '300px',
marginTop: '100px',
left: '0px',
top: '0px',
width: '1000px',
height: '760px',
});
for (const property of [
'transitionProperty', 'transitionDuration', 'transitionTimingFunction', 'position', 'zIndex',
] as const) {
assert.equal(restoring[property], magnified[property]);
}
assert.equal(resolvePaneMagnificationStyle(original, false, null, 1, origin), original);
});
test('two-pane magnification keeps the dormant pane geometry unchanged', () => {
assert.deepEqual(resolveTwoPaneMagnificationStyle('left', true, true), {
left: '12px', top: '12px', width: 'calc(100% - 24px)', height: 'calc(100% - 24px)', zIndex: 50,
+54 -4
View File
@@ -117,13 +117,62 @@ export function snapCssRectToDevicePixels(
};
}
export const PANE_MAGNIFICATION_DURATION_MS = 200;
export function resolvePaneMagnificationLayoutGeometry(
original: React.CSSProperties,
layoutOrigin?: { width?: number; height?: number },
): React.CSSProperties {
const resolveLength = (value: string | number | undefined, parentSize?: number) => {
if (typeof value === 'number') return `${value}px`;
if (typeof value === 'string' && value.endsWith('%') && parentSize !== undefined) {
return `${parseFloat(value) * parentSize / 100}px`;
}
return value;
};
return {
left: resolveLength(original.left, layoutOrigin?.width),
top: resolveLength(original.top, layoutOrigin?.height),
width: resolveLength(original.width, layoutOrigin?.width),
height: resolveLength(original.height, layoutOrigin?.height),
};
}
export function resolvePaneMagnificationStyle(
original: React.CSSProperties,
magnified: boolean,
surfaceBounds?: { left: number; top: number; width: number; height: number } | null,
devicePixelRatio = 1,
layoutOrigin?: { left: number; top: number; width?: number; height?: number },
): React.CSSProperties {
if (!magnified) return original;
// Keep the fixed overlay and transition while restoring too, so the split
// container cannot clip the pane before it has finished shrinking.
const transition: React.CSSProperties = surfaceBounds ? {
transitionProperty: 'left, top, width, height',
transitionDuration: `${PANE_MAGNIFICATION_DURATION_MS}ms`,
transitionTimingFunction: 'ease-out',
zIndex: 50,
} : {};
// Margins compensate for the containing-block switch without animating or
// transforming the terminal and its descendants. Local split offsets then
// keep the same viewport origin when fixed positioning starts or ends.
const fixedOrigin: React.CSSProperties = {
position: 'fixed',
...(layoutOrigin ? {
marginLeft: `${layoutOrigin.left}px`,
marginTop: `${layoutOrigin.top}px`,
} : {}),
};
if (!magnified) {
if (!surfaceBounds) return original;
// Percentage lengths must keep using the layout parent when fixed.
return {
...original,
...transition,
...fixedOrigin,
...resolvePaneMagnificationLayoutGeometry(original, layoutOrigin),
};
}
if (surfaceBounds) {
const snapped = snapCssRectToDevicePixels(
surfaceBounds.left + 12,
@@ -133,9 +182,10 @@ export function resolvePaneMagnificationStyle(
devicePixelRatio,
);
return {
position: 'fixed',
left: `${snapped.left}px`,
top: `${snapped.top}px`,
...transition,
...fixedOrigin,
left: `${snapped.left - (layoutOrigin?.left ?? 0)}px`,
top: `${snapped.top - (layoutOrigin?.top ?? 0)}px`,
width: `${snapped.width}px`,
height: `${snapped.height}px`,
zIndex: 50,