mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-27 20:00:51 +00:00
fix(terminal): preserve pane geometry through zoom and restore
This commit is contained in:
1 parent
6527d5596f
commit
f96e8a1256
4 files changed
+101
-11
No files matched your search
@@ -52,6 +52,7 @@ import type { ResolvedAppearance, TerminalAppearanceHostScope } from '../../doma
|
||||
import type { TerminalSidePanelAutoOpenTab } from '../../domain/terminalSidePanelAutoOpen';
|
||||
import type { SidePanelTool } from '../../domain/sidePanelLayout';
|
||||
import {
|
||||
PANE_MAGNIFICATION_DURATION_MS,
|
||||
resolveMagnifiedChromeBorderWidth,
|
||||
resolvePaneMagnificationStyle,
|
||||
type PaneMagnificationController,
|
||||
@@ -1454,22 +1455,36 @@ const TerminalPane: React.FC<TerminalPaneProps> = memo(({
|
||||
top: number;
|
||||
width: number;
|
||||
height: number;
|
||||
layoutOrigin: { left: number; top: 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();
|
||||
setMagnifiedSurfaceBounds({
|
||||
left: bounds.left,
|
||||
top: bounds.top,
|
||||
width: bounds.width,
|
||||
height: bounds.height,
|
||||
layoutOrigin: { left: origin.left, top: origin.top },
|
||||
});
|
||||
};
|
||||
update();
|
||||
@@ -1477,13 +1492,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 +1657,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,7 +21,7 @@ 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, /const magnifiedDevicePixelRatio = typeof window === 'undefined' \? 1 : \(window\.devicePixelRatio \|\| 1\)/);
|
||||
});
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
getAvailablePaneMagnificationController,
|
||||
getPaneMagnificationShortcutLabel,
|
||||
isPaneMagnificationSelectionValid,
|
||||
PANE_MAGNIFICATION_DURATION_MS,
|
||||
resolvePaneMagnificationCandidate,
|
||||
resolvePaneMagnificationStyle,
|
||||
resolveMagnifiedChromeBorderWidth,
|
||||
@@ -13,6 +14,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 +90,7 @@ test('magnification overlays the original layout without changing its rect', ()
|
||||
width: 1400,
|
||||
height: 900,
|
||||
}), {
|
||||
...geometryTransition,
|
||||
position: 'fixed',
|
||||
left: '132px',
|
||||
top: '92px',
|
||||
@@ -110,6 +118,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 +136,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 +149,48 @@ 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 };
|
||||
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('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,
|
||||
|
||||
@@ -117,13 +117,34 @@ export function snapCssRectToDevicePixels(
|
||||
};
|
||||
}
|
||||
|
||||
export const PANE_MAGNIFICATION_DURATION_MS = 200;
|
||||
|
||||
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 },
|
||||
): 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) return surfaceBounds ? { ...original, ...transition, ...fixedOrigin } : original;
|
||||
if (surfaceBounds) {
|
||||
const snapped = snapCssRectToDevicePixels(
|
||||
surfaceBounds.left + 12,
|
||||
@@ -133,9 +154,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,
|
||||
|
||||
Reference in new issue
Block a user