fix(desktop): respect local-origin tauri shell for directory access (#391)

* feat: enable local-origin desktop features and copy in terminal support

- Enable arbitrary web loads in desktop web content for TAURI apps.
- Guard directory dialog access behind local-origin origin check.
- Add copy-to-clipboard support for terminal selections via common shortcuts.

* fix: improve initial directory resolution and persistence in directory store
This commit is contained in:
Bohdan Triapitsyn
2026-02-11 20:07:44 +02:00
committed by GitHub
parent 844562749d
commit 3afe0bb45d
7 changed files with 111 additions and 22 deletions
@@ -377,6 +377,36 @@ const TerminalViewport = React.forwardRef<TerminalController, TerminalViewportPr
}
}, []);
const hasCopyableSelectionInViewport = React.useCallback((): boolean => {
if (typeof window === 'undefined') {
return false;
}
const selection = window.getSelection();
if (!selection) {
return false;
}
const text = selection.toString();
if (!text.trim()) {
return false;
}
const container = containerRef.current;
if (!container) {
return false;
}
const anchorNode = selection.anchorNode;
const focusNode = selection.focusNode;
if (anchorNode && !container.contains(anchorNode)) {
return false;
}
if (focusNode && !container.contains(focusNode)) {
return false;
}
return true;
}, []);
const resetWriteState = React.useCallback(() => {
pendingWriteRef.current = '';
if (writeScheduledRef.current !== null && typeof window !== 'undefined') {
@@ -1229,6 +1259,18 @@ const TerminalViewport = React.forwardRef<TerminalController, TerminalViewportPr
const handleHiddenKeyDown = React.useCallback(
(event: React.KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => {
event.stopPropagation();
const normalizedKey = event.key.toLowerCase();
const isMacCopyShortcut = event.metaKey && !event.ctrlKey && !event.altKey && normalizedKey === 'c';
const isWindowsLinuxCopyShortcut =
event.ctrlKey && event.shiftKey && !event.metaKey && !event.altKey && normalizedKey === 'c';
if ((isMacCopyShortcut || isWindowsLinuxCopyShortcut) && hasCopyableSelectionInViewport()) {
event.preventDefault();
void copySelectionToClipboard();
return;
}
const target = event.currentTarget as HTMLElement;
const nativeEvent = event.nativeEvent as KeyboardEvent | undefined;
if (nativeEvent?.isComposing) {
@@ -1272,7 +1314,7 @@ const TerminalViewport = React.forwardRef<TerminalController, TerminalViewportPr
scheduleKeyProbe(target);
},
[clearEditableValue, readEditableValue, scheduleKeyProbe]
[clearEditableValue, copySelectionToClipboard, hasCopyableSelectionInViewport, readEditableValue, scheduleKeyProbe]
);
const handleHiddenKeyUp = React.useCallback(