mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-22 16:10:50 +00:00
Related #4168 On ~1–1.2× displays the 1px rounded accent border around a magnified pane drops out at the corners, and a box that is not aligned to the device-pixel grid turns the stroke into a faint, doubled hairline. Snap the magnified terminal overlay (after the 12px inset) to integer device pixels, and use a 2px accent stroke when devicePixelRatio is below 1.5 on both the terminal and side-panel chrome. Higher-DPR displays keep the existing 1px stroke.
208 lines
6.6 KiB
TypeScript
208 lines
6.6 KiB
TypeScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
|
|
import {
|
|
getAvailablePaneMagnificationController,
|
|
getPaneMagnificationShortcutLabel,
|
|
isPaneMagnificationSelectionValid,
|
|
resolvePaneMagnificationCandidate,
|
|
resolvePaneMagnificationStyle,
|
|
resolveMagnifiedChromeBorderWidth,
|
|
resolveTwoPaneMagnificationStyle,
|
|
snapCssRectToDevicePixels,
|
|
type PaneMagnificationController,
|
|
} from './paneMagnification.ts';
|
|
|
|
test('selects the first controller that can magnify the active surface', () => {
|
|
const unavailable: PaneMagnificationController = {
|
|
getState: () => 'unavailable',
|
|
focus: () => false,
|
|
restore: () => false,
|
|
toggle: () => false,
|
|
};
|
|
const focusable: PaneMagnificationController = {
|
|
getState: () => 'focusable',
|
|
focus: () => true,
|
|
restore: () => false,
|
|
toggle: () => true,
|
|
};
|
|
|
|
assert.equal(
|
|
getAvailablePaneMagnificationController([null, unavailable, focusable]),
|
|
focusable,
|
|
);
|
|
assert.equal(getAvailablePaneMagnificationController([unavailable]), null);
|
|
});
|
|
|
|
test('invalidates magnification when its pane closes or changes tab ownership', () => {
|
|
const selection = {
|
|
tabId: 'workspace-1',
|
|
target: { kind: 'terminal' as const, sessionId: 'session-1' },
|
|
};
|
|
assert.equal(isPaneMagnificationSelectionValid(
|
|
selection,
|
|
[{ tabId: 'workspace-1', sessionId: 'session-1' }],
|
|
[],
|
|
), true);
|
|
assert.equal(isPaneMagnificationSelectionValid(
|
|
selection,
|
|
[{ tabId: 'session-1', sessionId: 'session-1' }],
|
|
[],
|
|
), false);
|
|
assert.equal(isPaneMagnificationSelectionValid(selection, [], []), false);
|
|
});
|
|
|
|
test('uses the configured shortcut label for the current platform', () => {
|
|
const bindings = [{ id: 'toggle-pane-zoom', mac: '⌥ + M', pc: 'Alt + M' }];
|
|
|
|
assert.equal(getPaneMagnificationShortcutLabel(bindings, 'mac'), '⌥+M');
|
|
assert.equal(getPaneMagnificationShortcutLabel(bindings, 'pc'), 'Alt+M');
|
|
assert.equal(getPaneMagnificationShortcutLabel(bindings, 'disabled'), '');
|
|
});
|
|
|
|
test('magnification overlays the original layout without changing its rect', () => {
|
|
const original = { left: '0px', top: '300px', width: '600px', height: '300px' };
|
|
|
|
assert.deepEqual(resolvePaneMagnificationStyle(original, false), original);
|
|
assert.deepEqual(resolvePaneMagnificationStyle(original, true), {
|
|
left: '12px',
|
|
top: '12px',
|
|
width: 'calc(100% - 24px)',
|
|
height: 'calc(100% - 24px)',
|
|
zIndex: 50,
|
|
});
|
|
assert.deepEqual(original, {
|
|
left: '0px',
|
|
top: '300px',
|
|
width: '600px',
|
|
height: '300px',
|
|
});
|
|
assert.deepEqual(resolvePaneMagnificationStyle(original, true, {
|
|
left: 120,
|
|
top: 80,
|
|
width: 1400,
|
|
height: 900,
|
|
}), {
|
|
position: 'fixed',
|
|
left: '132px',
|
|
top: '92px',
|
|
width: '1376px',
|
|
height: '876px',
|
|
zIndex: 50,
|
|
});
|
|
});
|
|
|
|
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).
|
|
assert.deepEqual(resolvePaneMagnificationStyle(original, true, {
|
|
left: 120,
|
|
top: 80,
|
|
width: 1400,
|
|
height: 900,
|
|
}, 1), {
|
|
position: 'fixed',
|
|
left: '132px',
|
|
top: '92px',
|
|
width: '1376px',
|
|
height: '876px',
|
|
zIndex: 50,
|
|
});
|
|
|
|
// 120.4+12=132.4 at 2x -> 264.8 rounds to 265 -> 132.5
|
|
// right: 120.4+1400-12=1508.4 at 2x -> 3016.8 rounds to 3017 -> 1508.5
|
|
const snapped = resolvePaneMagnificationStyle(original, true, {
|
|
left: 120.4,
|
|
top: 80.4,
|
|
width: 1400,
|
|
height: 900,
|
|
}, 2);
|
|
assert.deepEqual(snapped, {
|
|
position: 'fixed',
|
|
left: '132.5px',
|
|
top: '92.5px',
|
|
width: '1376px',
|
|
height: '876px',
|
|
zIndex: 50,
|
|
});
|
|
|
|
const rect = snapCssRectToDevicePixels(10.2, 20.2, 110.2, 80.2, 2);
|
|
assert.deepEqual(rect, { left: 10, top: 20, width: 100, height: 60 });
|
|
});
|
|
|
|
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,
|
|
});
|
|
assert.deepEqual(resolveTwoPaneMagnificationStyle('right', true, false), {
|
|
left: '50%', top: '0%', width: '50%', height: '100%', zIndex: 10,
|
|
});
|
|
assert.deepEqual(resolveTwoPaneMagnificationStyle('right', false, false), {
|
|
left: '0%', top: '50%', width: '100%', height: '50%', zIndex: 10,
|
|
});
|
|
});
|
|
|
|
test('resolves the last interacted pane without borrowing another tab target', () => {
|
|
const sidePane = { id: 'pane-sftp', tool: 'sftp' };
|
|
const current = {
|
|
tabId: 'workspace-other',
|
|
target: { kind: 'terminal' as const, sessionId: 'session-other' },
|
|
};
|
|
|
|
assert.deepEqual(resolvePaneMagnificationCandidate({
|
|
tabId: 'workspace-1',
|
|
terminalSessionIds: ['session-1'],
|
|
focusedSessionId: 'session-1',
|
|
sidePanelPanes: [sidePane],
|
|
lastTarget: { kind: 'side-panel', paneId: sidePane.id, tool: sidePane.tool },
|
|
current,
|
|
}), {
|
|
target: { kind: 'side-panel', paneId: sidePane.id, tool: sidePane.tool },
|
|
focused: false,
|
|
});
|
|
});
|
|
|
|
test('keyboard workspace focus overrides a stale terminal interaction', () => {
|
|
assert.deepEqual(resolvePaneMagnificationCandidate({
|
|
tabId: 'workspace-1',
|
|
terminalSessionIds: ['session-1', 'session-2'],
|
|
focusedSessionId: 'session-2',
|
|
sidePanelPanes: [],
|
|
lastTarget: { kind: 'terminal', sessionId: 'session-1' },
|
|
current: null,
|
|
}), {
|
|
target: { kind: 'terminal', sessionId: 'session-2' },
|
|
focused: false,
|
|
});
|
|
});
|
|
|
|
test('keeps a valid magnified pane focused and rejects a single-pane surface', () => {
|
|
const current = {
|
|
tabId: 'workspace-1',
|
|
target: { kind: 'terminal' as const, sessionId: 'session-2' },
|
|
};
|
|
assert.deepEqual(resolvePaneMagnificationCandidate({
|
|
tabId: 'workspace-1',
|
|
terminalSessionIds: ['session-1', 'session-2'],
|
|
focusedSessionId: 'session-1',
|
|
sidePanelPanes: [],
|
|
current,
|
|
}), { target: current.target, focused: true });
|
|
assert.equal(resolvePaneMagnificationCandidate({
|
|
tabId: 'workspace-1',
|
|
terminalSessionIds: ['session-1'],
|
|
focusedSessionId: 'session-1',
|
|
sidePanelPanes: [],
|
|
current: null,
|
|
}), null);
|
|
});
|