fix(ui): use a 1px continuous stroke for magnified pane chrome (#4168) (#4452)

Co-authored-by: Codex <codex@openai.com>
This commit is contained in:
陈大猫andCodex authored and GitHub committed 2026-11-26 22:25:32 +08:00
1 parent 6236f5bb95
commit 1009f131fe
6 files changed
+35 -40

No files matched your search

@@ -1,4 +1,5 @@
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import test from 'node:test';
import { JSDOM } from 'jsdom';
@@ -19,6 +20,17 @@ import {
resolveSidePanelPortalTarget,
} from './terminalLayerSidePanelSlots.tsx';
test('magnified side panels use a continuous 1px inset outline in the side panel accent', () => {
const source = readFileSync(new URL('./TerminalLayerSidePanelSection.tsx', import.meta.url), 'utf8');
const chromeStart = source.indexOf('className="absolute inset-3');
const chromeSource = source.slice(chromeStart, source.indexOf('\n >', chromeStart));
assert.match(chromeSource, /overflow-hidden rounded-md bg-background shadow-2xl/);
assert.match(chromeSource, /outline: `1px solid \$\{sidePanelTheme\.accent\}`/);
assert.match(chromeSource, /outlineOffset: -1/);
assert.doesNotMatch(chromeSource, /\bborder(?:Color|Width|Style)?\b/);
});
test('AI side panel shell can be force-hidden for layout isolation', () => {
assert.equal(getTerminalSidePanelShellWidth({
activeSidePanelTab: 'ai',
@@ -64,7 +64,7 @@ import { PersistentSidePanelPortal, SidePanelMountedContent } from './terminalLa
import { usePluginTerminalSidebar } from '../../application/state/usePluginTerminalSidebar';
import { PluginTerminalSidebarPageHost } from '../plugins/PluginTerminalSidebar';
import { PluginContributionIcon } from '../plugins/PluginContributionIcon';
import { getPaneMagnificationShortcutLabel, resolveMagnifiedChromeBorderWidth } from '../../domain/paneMagnification';
import { getPaneMagnificationShortcutLabel } from '../../domain/paneMagnification';
const MemoizedSidePanelMountedContent = memo(
SidePanelMountedContent,
@@ -1567,12 +1567,10 @@ function TerminalLayerSidePanelInner({ ctx, pluginSidebar }: { ctx: SidePanelCon
data-section="pane-magnification-backdrop"
/>
<div
className="absolute inset-3 flex flex-col overflow-hidden rounded-md border bg-background shadow-2xl animate-in fade-in zoom-in-95 duration-150"
className="absolute inset-3 flex flex-col overflow-hidden rounded-md bg-background shadow-2xl animate-in fade-in zoom-in-95 duration-150"
style={{
borderColor: sidePanelTheme.accent,
borderWidth: resolveMagnifiedChromeBorderWidth(
typeof window === 'undefined' ? 1 : (window.devicePixelRatio || 1),
),
outline: `1px solid ${sidePanelTheme.accent}`,
outlineOffset: -1,
backgroundColor: sidePanelTheme.termBg,
color: sidePanelTheme.termFg,
}}
@@ -53,7 +53,6 @@ import type { TerminalSidePanelAutoOpenTab } from '../../domain/terminalSidePane
import type { SidePanelTool } from '../../domain/sidePanelLayout';
import {
PANE_MAGNIFICATION_DURATION_MS,
resolveMagnifiedChromeBorderWidth,
resolvePaneMagnificationLayoutGeometry,
resolvePaneMagnificationStyle,
type PaneMagnificationController,
@@ -1643,14 +1642,14 @@ const TerminalPane: React.FC<TerminalPaneProps> = memo(({
"absolute bg-background",
inActiveWorkspace && "workspace-pane",
isVisible && "z-10",
magnifiedSurfaceBounds && "overflow-hidden rounded-md border shadow-2xl",
magnifiedSurfaceBounds && "overflow-hidden rounded-md shadow-2xl",
)}
style={{
...style,
borderColor: magnifiedSurfaceBounds ? sessionAppearanceTheme.colors.cursor : undefined,
borderWidth: magnifiedSurfaceBounds
? resolveMagnifiedChromeBorderWidth(magnifiedDevicePixelRatio)
outline: magnifiedSurfaceBounds
? `1px solid ${sessionAppearanceTheme.colors.cursor}`
: undefined,
outlineOffset: magnifiedSurfaceBounds ? -1 : undefined,
}}
tabIndex={-1}
onClick={handlePaneClick}
@@ -5,43 +5,43 @@ import React from "react";
import { act, create } from "react-test-renderer";
import { sidePanelLiveStore, SIDE_PANEL_INACTIVE_LIVE_SNAPSHOT } from "../../application/state/sidePanelLiveStore.ts";
import { createEmptyWorkspaceRoot } from "../../domain/workspace.ts";
import { resolveMagnifiedChromeBorderWidth } from "../../domain/paneMagnification.ts";
import { renderToStaticMarkup } from "react-dom/server";
import { TerminalLayerWorkspaceSection } from "./TerminalLayerWorkspaceSection.tsx";
test("terminal pane chrome follows retained surface bounds through restore", () => {
test("terminal pane chrome follows retained surface bounds through restore with a continuous 1px inset outline", () => {
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, /^\s*magnifiedSurfaceBounds && "overflow-hidden rounded-md border shadow-2xl",$/m);
assert.match(paneSource, /borderColor: magnifiedSurfaceBounds \? sessionAppearanceTheme\.colors\.cursor : undefined/);
assert.match(paneSource, /borderWidth: magnifiedSurfaceBounds\s*\? resolveMagnifiedChromeBorderWidth\(magnifiedDevicePixelRatio\)\s*: undefined/);
assert.match(paneSource, /^\s*magnifiedSurfaceBounds && "overflow-hidden rounded-md shadow-2xl",$/m);
assert.match(paneSource, /outline: magnifiedSurfaceBounds\s+\? `1px solid \$\{sessionAppearanceTheme\.colors\.cursor\}`\s+: undefined/);
assert.match(paneSource, /outlineOffset: magnifiedSurfaceBounds \? -1 : undefined/);
assert.doesNotMatch(paneSource, /\bborder(?:Color|Width|Style)?\b/);
});
test("restoring terminal chrome keeps its width and color until surface bounds clear", () => {
test("restoring terminal chrome keeps its 1px inset outline until surface bounds clear at any DPR", () => {
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"));
const styleSource = paneSource.match(/style=\{\{([\s\S]*?)\}\}/);
assert.ok(styleSource);
const resolveStyle = new Function(
"style", "isMagnified", "magnifiedSurfaceBounds", "sessionAppearanceTheme",
"magnifiedDevicePixelRatio", "resolveMagnifiedChromeBorderWidth",
"magnifiedDevicePixelRatio",
`return ({${styleSource[1]}});`,
);
const bounds = { left: 0, top: 80, width: 1200, height: 800 };
const theme = { colors: { cursor: "#0088ff" } };
for (const dpr of [1, 2]) {
const magnified = resolveStyle({}, true, bounds, theme, dpr, resolveMagnifiedChromeBorderWidth);
const restoring = resolveStyle({}, false, bounds, theme, dpr, resolveMagnifiedChromeBorderWidth);
for (const dpr of [1, 1.25, 1.5, 2, 3]) {
const magnified = resolveStyle({}, true, bounds, theme, dpr);
const restoring = resolveStyle({}, false, bounds, theme, dpr);
assert.deepEqual(restoring, magnified);
assert.equal(restoring.borderColor, theme.colors.cursor);
assert.equal(restoring.borderWidth, dpr === 1 ? 2 : 1);
assert.equal(restoring.outline, `1px solid ${theme.colors.cursor}`);
assert.equal(restoring.outlineOffset, -1);
for (const isMagnified of [false, true]) {
const cleared = resolveStyle({}, isMagnified, null, theme, dpr, resolveMagnifiedChromeBorderWidth);
assert.equal(cleared.borderColor, undefined);
assert.equal(cleared.borderWidth, undefined);
const cleared = resolveStyle({}, isMagnified, null, theme, dpr);
assert.equal(cleared.outline, undefined);
assert.equal(cleared.outlineOffset, undefined);
}
}
});
-10
View File
@@ -9,7 +9,6 @@ import {
resolvePaneMagnificationCandidate,
resolvePaneMagnificationLayoutGeometry,
resolvePaneMagnificationStyle,
resolveMagnifiedChromeBorderWidth,
resolveTwoPaneMagnificationStyle,
snapCssRectToDevicePixels,
type PaneMagnificationController,
@@ -101,15 +100,6 @@ test('magnification overlays the original layout without changing its rect', ()
});
});
test('magnified chrome uses a 2px accent stroke only below 1.5 device pixels', () => {
assert.equal(resolveMagnifiedChromeBorderWidth(1), 2);
assert.equal(resolveMagnifiedChromeBorderWidth(1.2), 2);
assert.equal(resolveMagnifiedChromeBorderWidth(1.49), 2);
assert.equal(resolveMagnifiedChromeBorderWidth(1.5), 1);
assert.equal(resolveMagnifiedChromeBorderWidth(2), 1);
assert.equal(resolveMagnifiedChromeBorderWidth(0), 1);
});
test('magnified surface bounds snap to the device-pixel grid after the 12px inset', () => {
const original = { left: '0px', top: '0px', width: '100px', height: '100px' };
// Integer CSS pixels at 1x stay unchanged (existing contract).
-4
View File
@@ -92,10 +92,6 @@ export function getPaneMagnificationShortcutLabel(
return (hotkeyScheme === 'mac' ? binding?.mac : binding?.pc)?.replace(/ \+ /g, '+') ?? '';
}
export function resolveMagnifiedChromeBorderWidth(devicePixelRatio = 1): number {
return devicePixelRatio > 0 && devicePixelRatio < 1.5 ? 2 : 1;
}
export function snapCssRectToDevicePixels(
left: number,
top: number,