Compare commits

...
3 changed files with 62 additions and 3 deletions

No files matched your search

@@ -0,0 +1,46 @@
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import test from 'node:test';
const source = readFileSync(new URL('./RemoteDesktopPane.tsx', import.meta.url), 'utf8');
test('RemoteDesktopPane keeps keyboard grab in visible solo and focus panes and honors split focus', () => {
const terminalLayerSource = readFileSync(new URL('../terminalLayer/TerminalLayerSupport.tsx', import.meta.url), 'utf8');
const paneProps = terminalLayerSource.match(/<LazyRemoteDesktopPane\b[\s\S]*?\/>/)?.[0];
assert.ok(paneProps, 'RemoteDesktopPane must be wired into the terminal layer');
assert.match(paneProps, /isVisible=\{isVisible\}/);
// Solo and focus modes have no split contention; only split siblings use the focus boolean.
assert.match(paneProps, /isFocused=\{paneState.mode === 'split' \? isFocusedPane : true\}/);
});
test('RemoteDesktopPane releases keyboard grab for an unfocused split sibling, hidden, disconnected, or view-only pane', () => {
assert.match(
source,
/useEffect\(\(\) => \{\s*if \(\(!isVisible \|\| !isFocused \|\| status !== 'connected' \|\| viewOnly\) && keyboardGrabActive\) \{\s*releaseKeyboardGrab\(\);\s*\}\s*\}, \[isFocused, isVisible, keyboardGrabActive, releaseKeyboardGrab, status, viewOnly\]\)/,
);
});
test('RemoteDesktopPane scopes all pane UI portals to the pane only in session fullscreen', () => {
assert.match(source, /import \{ PortalContainerProvider \} from '\.\.\/ui\/portal-container'/);
assert.match(source, /const \[portalContainer, setPortalContainer\] = useState<HTMLDivElement \| null>\(null\)/);
assert.match(source, /const paneContent = \([\s\S]*<RemoteDesktopToolbar[\s\S]*<RemoteDesktopAuditDialog/);
assert.match(
source,
/<PortalContainerProvider container=\{isFullscreen \? portalContainer : null\}>\s*\{paneContent\}\s*<\/PortalContainerProvider>/,
);
});
test('RemoteDesktopPane uses the same root for fullscreen ownership and the portal container', () => {
assert.match(
source,
/const setPaneRoot = useCallback\(\(node: HTMLDivElement \| null\) => \{\s*paneRootRef.current = node;\s*setPortalContainer\(node\);\s*\}, \[\]\)/,
);
assert.match(source, /const paneContent = \(\s*<div\s+ref=\{setPaneRoot\}/);
assert.match(
source,
/const root = paneRootRef.current;\s*setIsFullscreen\(Boolean\(root && document.fullscreenElement === root\)\)/,
);
assert.match(source, /document.addEventListener\('fullscreenchange', handleFsChange\)/);
assert.match(source, /document.removeEventListener\('fullscreenchange', handleFsChange\)/);
assert.match(source, /const root = paneRootRef.current;[\s\S]*root.requestFullscreen\(\)/);
});
+15 -2
View File
@@ -79,6 +79,7 @@ import {
VncProtocolIcon,
} from '../icons/RemoteDesktopIcons';
import { Button } from '../ui/button';
import { PortalContainerProvider } from '../ui/portal-container';
import { toast } from '../ui/toast';
import {
trustKnownRemoteDesktopCert,
@@ -208,6 +209,11 @@ export const RemoteDesktopPane: React.FC<RemoteDesktopPaneProps> = React.memo(({
const { t } = useI18n();
const isRdp = protocol === 'rdp';
const paneRootRef = useRef<HTMLDivElement | null>(null);
const [portalContainer, setPortalContainer] = useState<HTMLDivElement | null>(null);
const setPaneRoot = useCallback((node: HTMLDivElement | null) => {
paneRootRef.current = node;
setPortalContainer(node);
}, []);
const canvasAreaRef = useRef<HTMLDivElement | null>(null);
const canvasHandleRef = useRef<RemoteDesktopCanvasHandle | null>(null);
const activeBackendSessionIdRef = useRef<string | null>(null);
@@ -1747,9 +1753,9 @@ export const RemoteDesktopPane: React.FC<RemoteDesktopPaneProps> = React.memo(({
const showRemoteAppNotice =
isRdp && Boolean(spec.rdpConfig?.remoteApplicationMode) && !remoteAppBannerDismissed;
return (
const paneContent = (
<div
ref={paneRootRef}
ref={setPaneRoot}
className={cn(
'relative flex h-full w-full flex-col overflow-hidden bg-black text-foreground select-none',
keyboardGrabActive && 'ring-2 ring-inset ring-primary/80',
@@ -2309,6 +2315,13 @@ export const RemoteDesktopPane: React.FC<RemoteDesktopPaneProps> = React.memo(({
/>
</div>
);
// Fullscreen portals must stay inside the pane; windowed menus need to escape its overflow clipping.
return (
<PortalContainerProvider container={isFullscreen ? portalContainer : null}>
{paneContent}
</PortalContainerProvider>
);
});
RemoteDesktopPane.displayName = 'RemoteDesktopPane';
@@ -1871,7 +1871,7 @@ const TerminalPane: React.FC<TerminalPaneProps> = memo(({
identities={identities}
knownHosts={knownHosts}
isVisible={isVisible}
isFocused={isFocusedPane}
isFocused={paneState.mode === 'split' ? isFocusedPane : true}
inWorkspace={keepsWorkspacePresentation}
onStatusChange={handleRemoteDesktopStatusChange}
onCloseSession={onCloseSession}