18807b8ac2
Over plain http on a tailnet address the page is not a secure context and
navigator.clipboard is undefined, so the web engine refused every copy.
ClipboardReportingMessenger now answers clipboard calls through the
browser's legacy clipboard when the API is missing (web only, conditional
import): copy uses execCommand('copy') with a one-shot copy-event listener
(no focus or selection change); a paste key's Clipboard.getData takes the
browser's own paste event, the key reported not-handled so the browser
still fires it. A Paste button/menu says to use Ctrl+V or the https address.
Secure pages keep the engine path. Capture kit: --insecure and clipboard=.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
120 lines
6.9 KiB
Markdown
120 lines
6.9 KiB
Markdown
# Clipboard keys (copy/paste everywhere, Omarchy universal copy, terminal Ctrl+C)
|
|
|
|
Operator report: copying out of the web app was unreliable; the desktop's
|
|
universal copy key (Omarchy SUPER+C) worked everywhere but Pipelines; Ctrl+C
|
|
should not end the terminal session.
|
|
|
|
## Root causes
|
|
|
|
- **Universal copy/paste (confirmed in Chromium over CDP).** Omarchy's
|
|
SUPER+C (`/usr/share/omarchy/default/hypr/bindings/clipboard.lua`) sends
|
|
Ctrl+C with Hyprland `send_key_state`: the key event carries `ctrlKey`, but
|
|
no Ctrl key event is ever sent, while Super is physically held. Flutter's
|
|
web engine learns a modifier is down only from that modifier's own key
|
|
event (it synthesizes *releases* from the flags, never presses), so the
|
|
framework saw a plain `c`: the chat selection was not copied and the
|
|
terminal typed the letter. If the browser also reports Meta for the chord,
|
|
Ctrl+Meta+C matched no copy shortcut either. Physical Ctrl+C / Ctrl+Insert
|
|
worked. Paste into text fields mostly worked because the browser's own
|
|
paste follows the event flags.
|
|
- **Ctrl+C ending a terminal (confirmed with util-linux su 2.42).** Before
|
|
the login completes the terminal is `su -l <user>`: Ctrl+C at the
|
|
password prompt kills su with SIGINT and the terminal ends ("The login did
|
|
not complete"). After login, su 2.42 runs the shell in its own pty, so
|
|
Ctrl+C reaches the shell and the session survives (checked with real su in
|
|
a user namespace). No client path closes a tab on Ctrl+C.
|
|
|
|
## Fixes
|
|
|
|
- `lib/core/keyboard/key_modifier_sync.dart`: on the web, a sync in front of
|
|
the framework's key data handler reads the browser event's own modifier
|
|
flags (`window.event`) and presses (synthesized) the modifiers the flags
|
|
hold that the framework does not, releasing them with the chord's key.
|
|
Outside Apple platforms a held/merged Meta is released for Ctrl+C/V/X/A/
|
|
Insert and pressed again afterwards. Installed by `PipelinesBinding`
|
|
(`lib/application/pipelines_binding.dart`) once the services binding has
|
|
set its key handler.
|
|
- Terminal (`chat_shell_terminal_view.dart`): Ctrl+C with a selection
|
|
copies and clears it, never ^C; without one it is ^C; an injected Ctrl+C
|
|
(no Ctrl key held: the desktop's copy key) only ever copies. Shift+Insert
|
|
pastes (`chat_shell_terminal_shortcuts.dart`).
|
|
- Copy never fails silently: `ClipboardReportingMessenger`
|
|
(`lib/application/clipboard_failures.dart`) reports a refused
|
|
`Clipboard.setData`/`getData` reply as a snackbar ("Could not copy: …").
|
|
- Server (`internal/server/terminal_login.go`, `terminal_process.go`):
|
|
before the login completes Ctrl+C and Ctrl+\ are sent as Ctrl+U (erase the
|
|
typed password) and Ctrl+Z is dropped, so su is not killed or stopped.
|
|
|
|
## Evidence
|
|
|
|
Widget tests: `test/core/keyboard/`, `test/features/chat/ui/transcript/
|
|
chat_injected_clipboard_keys_test.dart`, `test/features/chat/conversation/
|
|
chat_composer_injected_paste_test.dart`, `test/features/chat/shell/
|
|
chat_shell_terminal_clipboard_keys_test.dart`, `test/application/
|
|
clipboard_failures_test.dart`; Go `TestTerminalCtrlCAtLoginPromptKeepsTheTerminal`.
|
|
|
|
Browser (headless Chromium, `--semantics false`, clipboard read back with
|
|
`navigator.clipboard.readText()`), scripts in `tool/capture/examples/
|
|
clipboard-*.json`: before the fix the Super+C sequences (Meta down, `c` with
|
|
Ctrl flags and no Ctrl key, both with and without Meta in the flags) left
|
|
the clipboard unchanged in the chat and the terminal; after it they copy
|
|
"Answer 19" / the terminal selection, Super+C with nothing selected sends no
|
|
^C, Super+V pastes once into the terminal and the composer, physical Ctrl+C
|
|
without a selection still sends ^C, and a rejected `writeText` shows "Could
|
|
not copy: the browser refused access to the clipboard".
|
|
|
|
Not verified: the real Hyprland session (whether it reports Meta with the
|
|
chord is covered both ways); text fields when the browser reports Ctrl and
|
|
Meta together (the browser's native paste may not run then). With Flutter
|
|
semantics enabled, copying the transcript after typing in the composer did
|
|
not copy before or after this change (semantics off works); not addressed.
|
|
|
|
## Copy and paste on an insecure (http) page
|
|
|
|
Operator report: over plain http on the tailnet address the page is not a
|
|
secure context, `navigator.clipboard` is undefined, and Flutter's web engine
|
|
refused every `Clipboard.setData`/`getData` ("Could not copy: Clipboard is
|
|
not available in the context."), so no copy worked.
|
|
|
|
`ClipboardReportingMessenger` now takes an `InsecureClipboard`
|
|
(`lib/application/insecure_clipboard.dart`; browser side
|
|
`insecure_clipboard_host_web.dart`, conditional import, null on VM/native),
|
|
which answers clipboard calls only when the Clipboard API is missing:
|
|
|
|
- `Clipboard.setData`: `document.execCommand('copy')` with a one-shot
|
|
capture `copy` listener that puts the text on the event's clipboardData.
|
|
No textarea is focused or selected, so the Flutter text-editing element
|
|
keeps focus, caret and any IME composition. Needs user activation (keys
|
|
and clicks give it). Every caller (keys, menus, buttons, terminal) goes
|
|
through it.
|
|
- `Clipboard.getData` during a key event (the terminal's Ctrl+V,
|
|
Ctrl+Shift+V, Shift+Insert, the injected Super+V): the `flutter/keyevent`
|
|
reply is rewritten to not-handled so the engine does not
|
|
`preventDefault` the key; the browser then fires `paste`, which a capture
|
|
listener on window consumes (preventDefault + stopImmediatePropagation, so
|
|
no double insertion) and returns as the clipboard text.
|
|
- `Clipboard.getData` outside a key event (terminal menu/toolbar Paste) has
|
|
no paste event: the reply is an error the messenger shows as "Could not
|
|
paste: this page isn't secure (http), ... Paste with Ctrl+V, or open the
|
|
https address." (Cmd+V on Apple). A refused copy says the same for copy.
|
|
- Secure pages: nothing is answered here; engine path unchanged.
|
|
|
|
Text fields (composer) already paste natively; the browser context menu's
|
|
Copy on a transcript selection is the browser's own copy (no Clipboard API).
|
|
|
|
Evidence (headless Chromium, `--insecure true`, clipboard read back from a
|
|
loopback scratch page): `tool/capture/examples/clipboard-insecure-chat.json`
|
|
(code-block and message copy buttons; composer Ctrl+V once) and
|
|
`clipboard-insecure-terminal.json` (Ctrl+V, Shift+Insert, Ctrl+Shift+V each
|
|
paste once; Ctrl+Shift+C and menu Copy copy; typing after a copy still
|
|
reaches the terminal; menu Paste shows the message). The super-c chat keys
|
|
(physical Ctrl+C, Super+C both flag forms, Ctrl+Insert) copy "Answer 19";
|
|
the same steps on a build without the handler leave the clipboard
|
|
unchanged. Secure-page examples (`clipboard-super-c-*`, `-super-v-composer`,
|
|
`-copy-refused`) behave as before. Tests: `test/application/
|
|
insecure_clipboard_test.dart`.
|
|
|
|
Not verified: Firefox/Safari; the browser's native context menu (headless
|
|
cannot drive it); a copy issued long after its click (an awaited network
|
|
call first, e.g. artifact URL copy) may outlive the user activation.
|