mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-20 15:19:16 +00:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a825c5dc2b |
No files matched your search
@@ -2601,18 +2601,6 @@ export const createXTermRuntime = (ctx: CreateXTermRuntimeContext): XTermRuntime
|
||||
}
|
||||
}
|
||||
|
||||
// Claim Shift+Insert as clipboard paste before Kitty/Win32 or xterm can
|
||||
// encode it as an Insert key, while preserving user shortcut precedence.
|
||||
if (
|
||||
e.key === "Insert" && e.shiftKey
|
||||
&& !e.ctrlKey && !e.altKey && !e.metaKey
|
||||
) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
void ctx.terminalContextActionsRef?.current?.onPaste?.();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Sogou/macOS CJK punctuation: keydown still reports ASCII "," while the
|
||||
// full-width "," arrives on insertText. Returning false (without
|
||||
// preventDefault) stops xterm/Kitty from sending the half-width key so the
|
||||
@@ -2788,6 +2776,15 @@ export const createXTermRuntime = (ctx: CreateXTermRuntimeContext): XTermRuntime
|
||||
};
|
||||
return true;
|
||||
}
|
||||
// xterm leaves Shift+Insert to the browser's native paste handler. Fan out
|
||||
// the clipboard data from onData instead of encoding an Insert key for
|
||||
// peers or treating the paste as that key's pending legacy data (#4142).
|
||||
if (
|
||||
e.key === "Insert" && e.shiftKey
|
||||
&& !e.ctrlKey && !e.altKey && !e.metaKey
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
if (!shouldDeferKittyKeyEvent(normalizedKittyEvent)) {
|
||||
const identity = kittyKeyIdentity(e);
|
||||
if (
|
||||
|
||||
@@ -7,7 +7,7 @@ import { buildSync } from "esbuild";
|
||||
import { JSDOM } from "jsdom";
|
||||
import ts from "typescript";
|
||||
|
||||
test("Shift+Insert uses onPaste and broadcasts clipboard bytes once across keyboard modes", async () => {
|
||||
test("native Shift+Insert broadcasts clipboard bytes once without an Insert key", async () => {
|
||||
const root = fileURLToPath(new URL("../../..", import.meta.url));
|
||||
const layer = readFileSync(new URL("../../TerminalLayer.tsx", import.meta.url), "utf8");
|
||||
const start = layer.indexOf(" const handleBroadcastInput = useCallback(");
|
||||
@@ -21,8 +21,6 @@ test("Shift+Insert uses onPaste and broadcasts clipboard bytes once across keybo
|
||||
contents: `
|
||||
export { createXTermRuntime } from "./components/terminal/runtime/createXTermRuntime";
|
||||
export { DEFAULT_TERMINAL_SETTINGS } from "./domain/models/terminal";
|
||||
export { DEFAULT_KEY_BINDINGS } from "./domain/models/keyBindings";
|
||||
export { pasteTextIntoTerminal } from "./components/terminal/runtime/terminalUserPaste";
|
||||
export { resolveTerminalBroadcastTargetIds } from "./domain/terminalBroadcast";
|
||||
export { dispatchKittyKeyboardBroadcastInput } from "./components/terminal/runtime/kittyKeyboardBroadcast";
|
||||
export * from "./components/terminal/runtime/terminalPacedBroadcast";
|
||||
@@ -52,8 +50,7 @@ test("Shift+Insert uses onPaste and broadcasts clipboard bytes once across keybo
|
||||
`);
|
||||
dom.window.eval(bundle);
|
||||
const results = await dom.window.eval(`(async () => {
|
||||
const {createXTermRuntime, DEFAULT_TERMINAL_SETTINGS, DEFAULT_KEY_BINDINGS,
|
||||
pasteTextIntoTerminal, resolveTerminalBroadcastTargetIds,
|
||||
const {createXTermRuntime, DEFAULT_TERMINAL_SETTINGS, resolveTerminalBroadcastTargetIds,
|
||||
dispatchKittyKeyboardBroadcastInput, markTerminalBroadcastUserInput,
|
||||
captureTerminalBroadcastInput, isTerminalBroadcastInputCurrent} = runtimeTest;
|
||||
const ref = current => ({current});
|
||||
@@ -63,123 +60,71 @@ test("Shift+Insert uses onPaste and broadcasts clipboard bytes once across keybo
|
||||
const canUseDirectSessionWriteFallback = () => true;
|
||||
const isTerminalSensitiveInputActive = () => false;
|
||||
const wires = new Map();
|
||||
const pasteCalls = new Map();
|
||||
const terminalBackend = {
|
||||
writeToSession:(id,data)=>wires.get(id).push(data), resizeSession(){}, openExternalAvailable:false,
|
||||
};
|
||||
${dispatcher}
|
||||
const make = (id, kittyKeyboardProtocolEnabled, options = {}) => {
|
||||
const make = (id, kittyKeyboardProtocolEnabled) => {
|
||||
const container = document.createElement('div'); document.body.appendChild(container);
|
||||
wires.set(id, []);
|
||||
pasteCalls.set(id, 0);
|
||||
const terminalContextActionsRef = ref({});
|
||||
const host = {id,label:id,hostname:'localhost',protocol:'ssh',sshInputCompatibility:false};
|
||||
const runtime = createXTermRuntime({
|
||||
return createXTermRuntime({
|
||||
container, host, getHost:()=>host, sessionId:id, sessionRef:ref(id), statusRef:ref('connected'),
|
||||
fontFamilyId:'jetbrains-mono',resolvedFontFamily:'monospace',fontSize:14,
|
||||
terminalTheme:{colors:{background:'#111111',foreground:'#eeeeee',cursor:'#ffffff',selection:'#444444'}},
|
||||
terminalSettingsRef:ref({...DEFAULT_TERMINAL_SETTINGS,rendererType:'dom',fontLigatures:false,cursorBlink:false}),
|
||||
terminalBackend,hotkeySchemeRef:ref('pc'),
|
||||
keyBindingsRef:ref(options.bindings ?? DEFAULT_KEY_BINDINGS),onHotkeyActionRef:ref(undefined),
|
||||
terminalContextActionsRef, snippetsRef:ref(options.snippets ?? []),
|
||||
onSnippetShortkeyRef:ref(options.onSnippet),
|
||||
terminalBackend,hotkeySchemeRef:ref('disabled'),keyBindingsRef:ref([]),onHotkeyActionRef:ref(undefined),
|
||||
isBroadcastEnabledRef:ref(true),onBroadcastInputRef:ref(handleBroadcastInput),
|
||||
commandBufferRef:ref(''),requestSearchFocus:options.onSearch ?? (()=>{}),kittyKeyboardProtocolEnabled,
|
||||
commandBufferRef:ref(''),requestSearchFocus(){},kittyKeyboardProtocolEnabled,
|
||||
});
|
||||
terminalContextActionsRef.current.onPaste = async () => {
|
||||
pasteCalls.set(id, pasteCalls.get(id) + 1);
|
||||
if (options.delayed) await new Promise(resolve=>setTimeout(resolve,10));
|
||||
pasteTextIntoTerminal(runtime.term, 'clipboard', {scrollOnPaste:false});
|
||||
};
|
||||
return runtime;
|
||||
};
|
||||
const results = [];
|
||||
const modes = [
|
||||
{name:'legacy',kitty:false,setup:''},
|
||||
{name:'native-kitty',kitty:false,setup:'\\x1b[>1u'},
|
||||
{name:'native-kitty-all-keys',kitty:false,setup:'\\x1b[>8u'},
|
||||
{name:'netcatty-kitty',kitty:true,setup:'\\x1b[>1u'},
|
||||
{name:'win32',kitty:false,setup:'\\x1b[?9001h'},
|
||||
];
|
||||
for (const mode of modes) {
|
||||
for (const bracketed of [false,true]) {
|
||||
for (const delayed of [true,false]) {
|
||||
for (const peerKitty of [false,true]) {
|
||||
const source = make('source', mode.kitty, {delayed}), peer = make('peer', peerKitty);
|
||||
try {
|
||||
sessionsRef.current = ['source','peer'].map(id=>({id,protocol:'ssh',workspaceId:'workspace'}));
|
||||
if (mode.setup) await new Promise(resolve=>source.term.write(mode.setup,resolve));
|
||||
if (peerKitty) await new Promise(resolve=>peer.term.write('\\x1b[>8u',resolve));
|
||||
if (bracketed) await new Promise(resolve=>source.term.write('\\x1b[?2004h',resolve));
|
||||
const key = new KeyboardEvent('keydown', {
|
||||
bubbles:true,cancelable:true,key:'Insert',code:'Insert',keyCode:45,shiftKey:true,
|
||||
});
|
||||
source.term.textarea.dispatchEvent(key);
|
||||
if (delayed) await new Promise(resolve=>setTimeout(resolve,20));
|
||||
source.term.textarea.dispatchEvent(new KeyboardEvent('keyup', {
|
||||
bubbles:true,key:'Insert',code:'Insert',keyCode:45,shiftKey:true,
|
||||
}));
|
||||
results.push({mode:mode.name,bracketed,delayed,peerKitty,pasteCalls:pasteCalls.get('source'),
|
||||
prevented:key.defaultPrevented,source:[...wires.get('source')],peer:[...wires.get('peer')]});
|
||||
// Ordinary Insert still uses the physical-key broadcast path.
|
||||
if (!peerKitty && mode.name !== 'win32') {
|
||||
wires.get('source').length=0; wires.get('peer').length=0;
|
||||
source.term.textarea.dispatchEvent(new KeyboardEvent('keydown', {
|
||||
bubbles:true,cancelable:true,key:'Insert',code:'Insert',keyCode:45,
|
||||
}));
|
||||
results.push({plainInsert:true,mode:mode.name,pasteCalls:pasteCalls.get('source'),
|
||||
source:[...wires.get('source')],peer:[...wires.get('peer')]});
|
||||
}
|
||||
for (const bracketed of [false,true]) {
|
||||
for (const delayed of [true,false]) {
|
||||
for (const peerKitty of [false,true]) {
|
||||
const source = make('source', false), peer = make('peer', peerKitty);
|
||||
try {
|
||||
sessionsRef.current = ['source','peer'].map(id=>({id,protocol:'ssh',workspaceId:'workspace'}));
|
||||
if (peerKitty) await new Promise(resolve=>peer.term.write('\\x1b[>8u',resolve));
|
||||
if (bracketed) await new Promise(resolve=>source.term.write('\\x1b[?2004h',resolve));
|
||||
const key = new KeyboardEvent('keydown', {
|
||||
bubbles:true,cancelable:true,key:'Insert',code:'Insert',keyCode:45,shiftKey:true,
|
||||
});
|
||||
source.term.textarea.dispatchEvent(key);
|
||||
const beforePaste = [...wires.get('peer')];
|
||||
if (delayed) await new Promise(resolve=>setTimeout(resolve,10));
|
||||
// Supply the native clipboard event which Chromium emits for this chord.
|
||||
const paste = new Event('paste', {bubbles:true,cancelable:true});
|
||||
Object.defineProperty(paste,'clipboardData',{value:{getData:()=> 'clipboard'}});
|
||||
source.term.textarea.dispatchEvent(paste);
|
||||
source.term.textarea.dispatchEvent(new KeyboardEvent('keyup', {
|
||||
bubbles:true,key:'Insert',code:'Insert',keyCode:45,shiftKey:true,
|
||||
}));
|
||||
results.push({bracketed,delayed,peerKitty,beforePaste,
|
||||
prevented:key.defaultPrevented,source:[...wires.get('source')],peer:[...wires.get('peer')]});
|
||||
// Ordinary Insert still uses the physical-key broadcast path.
|
||||
if (!peerKitty) {
|
||||
wires.get('source').length=0; wires.get('peer').length=0;
|
||||
const pasteShortcut = new KeyboardEvent('keydown', {
|
||||
bubbles:true,cancelable:true,key:'V',code:'KeyV',keyCode:86,ctrlKey:true,shiftKey:true,
|
||||
});
|
||||
source.term.textarea.dispatchEvent(pasteShortcut);
|
||||
if (delayed) await new Promise(resolve=>setTimeout(resolve,20));
|
||||
source.term.textarea.dispatchEvent(new KeyboardEvent('keyup', {
|
||||
bubbles:true,key:'V',code:'KeyV',keyCode:86,ctrlKey:true,shiftKey:true,
|
||||
source.term.textarea.dispatchEvent(new KeyboardEvent('keydown', {
|
||||
bubbles:true,cancelable:true,key:'Insert',code:'Insert',keyCode:45,
|
||||
}));
|
||||
results.push({configuredPaste:true,mode:mode.name,bracketed,pasteCalls:pasteCalls.get('source'),
|
||||
prevented:pasteShortcut.defaultPrevented,source:[...wires.get('source')],peer:[...wires.get('peer')]});
|
||||
} finally { source.dispose(); peer.dispose(); }
|
||||
}
|
||||
results.push({plainInsert:true,source:[...wires.get('source')],peer:[...wires.get('peer')]});
|
||||
}
|
||||
} finally { source.dispose(); peer.dispose(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const shortcut of ['binding','snippet']) {
|
||||
let searchCalls = 0, snippetCalls = 0;
|
||||
const source = make('source', true, shortcut === 'binding'
|
||||
? {onSearch:()=>searchCalls++,bindings:DEFAULT_KEY_BINDINGS.map(binding=>binding.action === 'searchTerminal'
|
||||
? {...binding,pc:'Shift + Insert'} : binding)}
|
||||
: {snippets:[{id:'snippet',shortkey:'Shift + Insert'}],onSnippet:()=>snippetCalls++});
|
||||
try {
|
||||
await new Promise(resolve=>source.term.write('\\x1b[>1u',resolve));
|
||||
source.term.textarea.dispatchEvent(new KeyboardEvent('keydown', {
|
||||
bubbles:true,cancelable:true,key:'Insert',code:'Insert',keyCode:45,shiftKey:true,
|
||||
}));
|
||||
results.push({shortcut,pasteCalls:pasteCalls.get('source'),snippetCalls,searchCalls,
|
||||
source:[...wires.get('source')]});
|
||||
} finally { source.dispose(); }
|
||||
}
|
||||
return JSON.stringify(results);
|
||||
})()`);
|
||||
for (const result of JSON.parse(results)) {
|
||||
if (result.plainInsert) {
|
||||
assert.equal(result.pasteCalls, 1);
|
||||
assert.deepEqual(result.source, ["\x1b[2~"]);
|
||||
assert.deepEqual(result.peer, ["\x1b[2~"]);
|
||||
continue;
|
||||
}
|
||||
if (result.shortcut) {
|
||||
assert.equal(result.pasteCalls, 0, result.shortcut);
|
||||
assert.equal(result.snippetCalls, result.shortcut === 'snippet' ? 1 : 0);
|
||||
assert.equal(result.searchCalls, result.shortcut === 'binding' ? 1 : 0);
|
||||
assert.deepEqual(result.source, []);
|
||||
continue;
|
||||
}
|
||||
const label = JSON.stringify(result);
|
||||
assert.equal(result.pasteCalls, result.configuredPaste ? 2 : 1, label);
|
||||
assert.equal(result.prevented, true, label);
|
||||
assert.deepEqual(result.beforePaste, [], label);
|
||||
assert.equal(result.prevented, false, "native paste must remain enabled: " + label);
|
||||
const expected = result.bracketed ? "\x1b[200~clipboard\x1b[201~" : "clipboard";
|
||||
assert.deepEqual(result.source, [expected], label);
|
||||
assert.deepEqual(result.peer, [expected], label);
|
||||
|
||||
@@ -374,14 +374,3 @@ test('side panel close button stays visible at every panel width', () => {
|
||||
assert.match(closeSlice, /className="h-7 w-7 shrink-0 rounded-md p-0 hover:bg-transparent"/);
|
||||
assert.doesNotMatch(closeSlice, /\bhidden\b|max-(sm|md|lg|xl):/);
|
||||
});
|
||||
|
||||
test('magnified side-panel chrome thickens the accent stroke on low-DPR displays', () => {
|
||||
const source = readFileSync(new URL('./TerminalLayerSidePanelSection.tsx', import.meta.url), 'utf8');
|
||||
const overlay = source.slice(
|
||||
source.indexOf('data-section="pane-magnification-overlay"'),
|
||||
source.indexOf('data-section="pane-magnification-content"'),
|
||||
);
|
||||
assert.match(overlay, /overflow-hidden rounded-md border bg-background shadow-2xl/);
|
||||
assert.match(overlay, /borderColor: sidePanelTheme\.accent,/);
|
||||
assert.match(overlay, /resolveMagnifiedChromeBorderWidth\(/);
|
||||
});
|
||||
@@ -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,
|
||||
@@ -1104,6 +1104,7 @@ function TerminalLayerSidePanelInner({ ctx, pluginSidebar }: { ctx: SidePanelCon
|
||||
const activeMagnifiedPane = !!activeTabId && magnifiedPane?.tabId === activeTabId
|
||||
? magnifiedPane
|
||||
: null;
|
||||
const devicePixelRatio = typeof window === 'undefined' ? 1 : window.devicePixelRatio || 1;
|
||||
const magnifiedSidePane = activeMagnifiedPane?.target.kind === 'side-panel'
|
||||
? activeSidePanelPanes.find((pane) => pane.id === activeMagnifiedPane.target.paneId) ?? null
|
||||
: null;
|
||||
@@ -1545,9 +1546,7 @@ function TerminalLayerSidePanelInner({ ctx, pluginSidebar }: { ctx: SidePanelCon
|
||||
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"
|
||||
style={{
|
||||
borderColor: sidePanelTheme.accent,
|
||||
borderWidth: resolveMagnifiedChromeBorderWidth(
|
||||
typeof window === 'undefined' ? 1 : (window.devicePixelRatio || 1),
|
||||
),
|
||||
borderWidth: devicePixelRatio < 1.5 ? 2 : 1,
|
||||
backgroundColor: sidePanelTheme.termBg,
|
||||
color: sidePanelTheme.termFg,
|
||||
}}
|
||||
|
||||
@@ -52,7 +52,6 @@ import type { ResolvedAppearance, TerminalAppearanceHostScope } from '../../doma
|
||||
import type { TerminalSidePanelAutoOpenTab } from '../../domain/terminalSidePanelAutoOpen';
|
||||
import type { SidePanelTool } from '../../domain/sidePanelLayout';
|
||||
import {
|
||||
resolveMagnifiedChromeBorderWidth,
|
||||
resolvePaneMagnificationStyle,
|
||||
type PaneMagnificationController,
|
||||
type PaneMagnificationTarget,
|
||||
@@ -1440,12 +1439,12 @@ const TerminalPane: React.FC<TerminalPaneProps> = memo(({
|
||||
observer.observe(surface);
|
||||
return () => observer.disconnect();
|
||||
}, [isMagnified]);
|
||||
const magnifiedDevicePixelRatio = typeof window === 'undefined' ? 1 : (window.devicePixelRatio || 1);
|
||||
const devicePixelRatio = typeof window === 'undefined' ? 1 : window.devicePixelRatio || 1;
|
||||
const style: React.CSSProperties = resolvePaneMagnificationStyle(
|
||||
layoutStyle,
|
||||
isMagnified && !!magnifiedSurfaceBounds,
|
||||
magnifiedSurfaceBounds,
|
||||
magnifiedDevicePixelRatio,
|
||||
devicePixelRatio,
|
||||
);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
@@ -1608,9 +1607,7 @@ const TerminalPane: React.FC<TerminalPaneProps> = memo(({
|
||||
style={{
|
||||
...style,
|
||||
borderColor: isMagnified && magnifiedSurfaceBounds ? sessionAppearanceTheme.colors.cursor : undefined,
|
||||
borderWidth: isMagnified && magnifiedSurfaceBounds
|
||||
? resolveMagnifiedChromeBorderWidth(magnifiedDevicePixelRatio)
|
||||
: undefined,
|
||||
borderWidth: isMagnified && magnifiedSurfaceBounds ? (devicePixelRatio < 1.5 ? 2 : 1) : undefined,
|
||||
}}
|
||||
tabIndex={-1}
|
||||
onClick={handlePaneClick}
|
||||
|
||||
@@ -15,14 +15,17 @@ test("magnified terminal panes use the resolved terminal accent for border chrom
|
||||
|
||||
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\)/);
|
||||
assert.match(source, /const devicePixelRatio = typeof window === 'undefined' \? 1 : window\.devicePixelRatio \|\| 1;/);
|
||||
assert.match(source, /resolvePaneMagnificationStyle\(\s*layoutStyle,\s*isMagnified && !!magnifiedSurfaceBounds,\s*magnifiedSurfaceBounds,\s*devicePixelRatio,\s*\)/);
|
||||
assert.match(paneSource, /borderWidth: isMagnified && magnifiedSurfaceBounds \? \(devicePixelRatio < 1\.5 \? 2 : 1\) : undefined/);
|
||||
});
|
||||
|
||||
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, /const magnifiedDevicePixelRatio = typeof window === 'undefined' \? 1 : \(window\.devicePixelRatio \|\| 1\)/);
|
||||
test("magnified side-panel chrome thickens its accent border only at low DPR", () => {
|
||||
const source = readFileSync(new URL("./TerminalLayerSidePanelSection.tsx", import.meta.url), "utf8");
|
||||
const overlaySource = source.slice(source.indexOf('{overlayRoot && magnifiedSidePane && createPortal('));
|
||||
|
||||
assert.match(source, /const devicePixelRatio = typeof window === 'undefined' \? 1 : window\.devicePixelRatio \|\| 1;/);
|
||||
assert.match(overlaySource, /borderColor: sidePanelTheme\.accent,\s*borderWidth: devicePixelRatio < 1\.5 \? 2 : 1,/);
|
||||
});
|
||||
|
||||
test("terminal keyboard focus updates the pane selected for magnification", () => {
|
||||
|
||||
@@ -7,9 +7,7 @@ import {
|
||||
isPaneMagnificationSelectionValid,
|
||||
resolvePaneMagnificationCandidate,
|
||||
resolvePaneMagnificationStyle,
|
||||
resolveMagnifiedChromeBorderWidth,
|
||||
resolveTwoPaneMagnificationStyle,
|
||||
snapCssRectToDevicePixels,
|
||||
type PaneMagnificationController,
|
||||
} from './paneMagnification.ts';
|
||||
|
||||
@@ -92,52 +90,36 @@ 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('magnification snaps final inset edges at the default DPR of 1', () => {
|
||||
assert.deepEqual(resolvePaneMagnificationStyle({}, true, {
|
||||
left: 120.3, top: 80.6, width: 1400.4, height: 900.6,
|
||||
}), {
|
||||
position: 'fixed',
|
||||
left: '132px', top: '93px', width: '1377px', height: '876px', zIndex: 50,
|
||||
});
|
||||
});
|
||||
|
||||
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,
|
||||
for (const [devicePixelRatio, expectedEdges] of [
|
||||
[1, [132, 93, 1509, 969]],
|
||||
[1.2, [159, 111, 1810, 1163]],
|
||||
[1.25, [165, 116, 1886, 1212]],
|
||||
[1.5, [198, 139, 2263, 1454]],
|
||||
[2, [265, 185, 3017, 1938]],
|
||||
] as const) {
|
||||
test(`magnification rounds each inset edge to device pixels at DPR ${devicePixelRatio}`, () => {
|
||||
const bounds = { left: 120.3, top: 80.6, width: 1400.4, height: 900.6 };
|
||||
const original = { left: '10.3px', width: '600.4px' };
|
||||
assert.equal(resolvePaneMagnificationStyle(original, false, bounds, devicePixelRatio), original);
|
||||
const style = resolvePaneMagnificationStyle(original, true, bounds, devicePixelRatio);
|
||||
const left = Number.parseFloat(style.left as string);
|
||||
const top = Number.parseFloat(style.top as string);
|
||||
const right = left + Number.parseFloat(style.width as string);
|
||||
const bottom = top + Number.parseFloat(style.height as string);
|
||||
for (const [index, edge] of [left, top, right, bottom].entries()) {
|
||||
assert.ok(Math.abs(edge * devicePixelRatio - expectedEdges[index]) < 1e-9);
|
||||
}
|
||||
});
|
||||
|
||||
// 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), {
|
||||
|
||||
@@ -92,31 +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,
|
||||
right: number,
|
||||
bottom: number,
|
||||
devicePixelRatio = 1,
|
||||
): { left: number; top: number; width: number; height: number } {
|
||||
const dpr = devicePixelRatio > 0 ? devicePixelRatio : 1;
|
||||
const snap = (value: number) => Math.round(value * dpr) / dpr;
|
||||
const snappedLeft = snap(left);
|
||||
const snappedTop = snap(top);
|
||||
const snappedRight = snap(right);
|
||||
const snappedBottom = snap(bottom);
|
||||
return {
|
||||
left: snappedLeft,
|
||||
top: snappedTop,
|
||||
width: Math.max(0, snappedRight - snappedLeft),
|
||||
height: Math.max(0, snappedBottom - snappedTop),
|
||||
};
|
||||
}
|
||||
|
||||
export function resolvePaneMagnificationStyle(
|
||||
original: React.CSSProperties,
|
||||
magnified: boolean,
|
||||
@@ -125,19 +100,17 @@ export function resolvePaneMagnificationStyle(
|
||||
): React.CSSProperties {
|
||||
if (!magnified) return original;
|
||||
if (surfaceBounds) {
|
||||
const snapped = snapCssRectToDevicePixels(
|
||||
surfaceBounds.left + 12,
|
||||
surfaceBounds.top + 12,
|
||||
surfaceBounds.left + surfaceBounds.width - 12,
|
||||
surfaceBounds.top + surfaceBounds.height - 12,
|
||||
devicePixelRatio,
|
||||
);
|
||||
const snap = (value: number) => Math.round(value * devicePixelRatio) / devicePixelRatio;
|
||||
const left = snap(surfaceBounds.left + 12);
|
||||
const top = snap(surfaceBounds.top + 12);
|
||||
const right = snap(surfaceBounds.left + surfaceBounds.width - 12);
|
||||
const bottom = snap(surfaceBounds.top + surfaceBounds.height - 12);
|
||||
return {
|
||||
position: 'fixed',
|
||||
left: `${snapped.left}px`,
|
||||
top: `${snapped.top}px`,
|
||||
width: `${snapped.width}px`,
|
||||
height: `${snapped.height}px`,
|
||||
left: `${left}px`,
|
||||
top: `${top}px`,
|
||||
width: `${Math.max(0, right - left)}px`,
|
||||
height: `${Math.max(0, bottom - top)}px`,
|
||||
zIndex: 50,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -70,10 +70,6 @@ const CMD_PROMPT_PATTERN = /^[A-Za-z]:(?:\\[^<>"|]*)?>$/;
|
||||
// the final `]` before `$`/`#` is the delimiter.
|
||||
const POSIX_PROMPT_PATTERN = /^(?:[^\s@]+@[^\s:]+(?::[^\n\r]*)?|\[[^\s@\]]+@[^\s\]:]+(?:\s+[^\n\r]+)?\])[#$]$/;
|
||||
|
||||
// Bracket PS1 without @host, with bash `\t` time: `[\u \t \w]$` -> `[root 12:04:23 ~]$` (#4276).
|
||||
// Require HH:MM:SS so loose `[word]$` output cannot count as idle.
|
||||
const BRACKET_TIME_POSIX_PROMPT_PATTERN = /^\[[^\s@\]]+\s+\d{2}:\d{2}:\d{2}(?:\s+[^\n\r\]]+)?\][#$]$/;
|
||||
|
||||
// Space-separated bash PS1 `\u@\h \w $ ` renders as `user@host ~ $`.
|
||||
// macOS ships zsh with `%n@%m %1~ %#`, which renders as
|
||||
// `user@host ~ %` / `user@host My Project %`; privileged shells end in `#`.
|
||||
@@ -141,7 +137,6 @@ function isDefaultPosixPromptLine(line) {
|
||||
const withoutEnvPrefix = normalized.replace(/^\([^()\n\r]+\)\s+/, "");
|
||||
return (
|
||||
POSIX_PROMPT_PATTERN.test(withoutEnvPrefix) ||
|
||||
BRACKET_TIME_POSIX_PROMPT_PATTERN.test(withoutEnvPrefix) ||
|
||||
PAREN_POSIX_PROMPT_PATTERN.test(withoutEnvPrefix) ||
|
||||
ALPINE_PROMPT_PATTERN.test(withoutEnvPrefix) ||
|
||||
ZSH_PROMPT_PATTERN.test(withoutEnvPrefix) ||
|
||||
|
||||
@@ -192,30 +192,6 @@ test("isDefaultPosixPromptLine matches classic user@host prompts", () => {
|
||||
assert.equal(isDefaultPosixPromptLine(""), false);
|
||||
});
|
||||
|
||||
test("recognizes bracketed time prompts without a hostname and preserves trailing space", () => {
|
||||
for (const prompt of [
|
||||
"[root 12:04:23 ~]$",
|
||||
"[root 12:04:23 ~]$ ",
|
||||
"[alice 00:00:00 /var/log]# ",
|
||||
"[alice-admin 23:59:59 ~/src]$ ",
|
||||
]) {
|
||||
assert.equal(isDefaultPosixPromptLine(prompt), true, prompt);
|
||||
assert.equal(extractTrailingIdlePrompt(`welcome\r\n${prompt}`), prompt, prompt);
|
||||
}
|
||||
});
|
||||
|
||||
test("bracketed time prompt recognition rejects pending input and prompts without time", () => {
|
||||
for (const line of [
|
||||
"[root 12:04:23 ~]$ hostname",
|
||||
"[root 12:04:23 ~]$ echo $",
|
||||
"[root ~]$",
|
||||
"[word]$",
|
||||
]) {
|
||||
assert.equal(isDefaultPosixPromptLine(line), false, line);
|
||||
assert.equal(extractTrailingIdlePrompt(`welcome\r\n${line}`), "", line);
|
||||
}
|
||||
});
|
||||
|
||||
test("recognizes space-separated Bash idle prompts and preserves trailing whitespace", () => {
|
||||
for (const prompt of [
|
||||
"root@VM-Q7L4M8P2 ~ $",
|
||||
@@ -512,13 +488,6 @@ test("extracts a trailing RHEL-family bracketed idle prompt", () => {
|
||||
assert.equal(extractTrailingIdlePrompt("welcome\r\nroot@host ~#"), "");
|
||||
});
|
||||
|
||||
test("extractTrailingIdlePrompt recognizes an ANSI-colored bracketed time prompt", () => {
|
||||
assert.equal(
|
||||
extractTrailingIdlePrompt("welcome\r\n[\x1b[1;34mroot \x1b[1;36m12:04:23 \x1b[1;32m~\x1b[0m]$ "),
|
||||
"[root 12:04:23 ~]$ ",
|
||||
);
|
||||
});
|
||||
|
||||
test("extractTrailingIdlePrompt recognizes a two-line user@host then bare $/# PS1", () => {
|
||||
// export PS1="\u@\h: \w\n$ " paints the host line, then a lone "$ ".
|
||||
// The cached prompt must keep both lines so a lone "$" cannot satisfy endsWith.
|
||||
@@ -1264,14 +1233,6 @@ test("trackSessionIdlePrompt and getFreshIdlePrompt accept an Oracle/RHEL bracke
|
||||
assert.equal(getFreshIdlePrompt(bracketedPath), "[user@host My [Project]]$ ");
|
||||
});
|
||||
|
||||
test("trackSessionIdlePrompt and getFreshIdlePrompt accept a bracketed time prompt", () => {
|
||||
const session = {};
|
||||
const prompt = "[root 12:04:23 ~]$ ";
|
||||
assert.equal(trackSessionIdlePrompt(session, `Last login...\r\n${prompt}`), prompt);
|
||||
assert.equal(session.lastIdlePrompt, prompt);
|
||||
assert.equal(getFreshIdlePrompt(session), prompt);
|
||||
});
|
||||
|
||||
test("visible idle prompt survives a PSReadLine erase that leaves the raw tail dirty", () => {
|
||||
// PSReadLine echoes the pending-input clear prefix (`ggd2147483647d` / `i`),
|
||||
// then homes the cursor and erases those keys with CSI. stripAnsi drops the
|
||||
|
||||
Reference in new issue
Block a user