Skip to content

Mac: ⌘C, ⌘V, ⌘X, ⌘A and ⌘Z work in the window's text fields (#340) - #352

Open
sundarshahi wants to merge 2 commits into
libracoder:mainfrom
sundarshahi:fix/340-edit-menu
Open

sundarshahi wants to merge 2 commits into
libracoder:mainfrom
sundarshahi:fix/340-edit-menu

Conversation

@sundarshahi

Copy link
Copy Markdown

What this changes and why

On the Mac, ⌘C, ⌘V, ⌘X, ⌘A and ⌘Z do nothing in the window's text fields (Settings → proxy, registry logins, env editors) and the Mac beeps. AppKit gives these keys to a WKWebView through the menu bar's Edit menu, and Kiri's menu bar has only the app menu and View. This adds the standard Edit menu.

Fixes #340

Problem

  • main_menu (crates/kiri/src/ui/mac.rs:261) builds the app menu and View only.
  • AppKit offers ⌘-keys to the window first. WKWebView offers them to the page. Anything the page doesn't cancel goes to the menu bar's key equivalents.
  • No menu item answers ⌘V, so nothing sends paste: down the responder chain to the focused field, and the Mac beeps.
  • index.html already says so ("The window has no Edit menu, which is where the Mac gets Copy's key from"). That's why Logs: select and copy the text #177 added a page handler for ⌘C on selected log text. Text fields were left without one.

Fix

  • An Edit menu between the app menu and View: Undo ⌘Z, Redo ⇧⌘Z, Cut, Copy, Paste, Select All, using AppKit's standard selectors (undo: redo: cut: copy: paste: selectAll:). It's rebuilt with the rest of the menu bar when the language changes (relang).
  • Keys the page handles itself are unchanged. The page still sees each key first, and these handlers cancel it, so the menu never gets it:
    • the terminal's ⌘C and ⌘V (htKey calls preventDefault);
    • a list's ⌘A, which picks rows.
  • The page's own ⌘C for selected text (Logs: select and copy the text #177) now runs on Windows and Linux only. On the Mac, Edit → Copy does it. Left as it was, ⌘C would copy twice: the page's plain-text copy and the menu's rich-text copy, in no fixed order. tests/ui/logselect.js now runs as all three systems:
    • on Windows and Linux, the page sends the copy;
    • on the Mac, it leaves it to the menu.
  • Words: "Cut", "Redo" and "Select All" are new keys in all 37 languages. Each follows its file's existing Copy, Paste and Undo style: a verb in de, fr and ru, a noun in bg and hu. "Select All" uses each file's existing "Select all" words. "Edit" reuses the existing key.

On Windows and Linux, WebView2 and WebKitGTK handle Ctrl+C and Ctrl+V in text fields themselves, so nothing changes there. I didn't test those two systems by hand, so I kept the page's Ctrl+C handler there as it was. If you'd rather remove it everywhere, happy to.

How you tested it

macOS 27 (Apple silicon), cargo build -p kiri, target/debug/kiri ui.

The keys were pressed from inside the app, through the same path a keyboard uses. A temporary harness (not in this PR) built real NSEvent key-downs with ⌘ (⇧⌘ for redo) and passed them to NSApp.sendEvent:, aimed at a focused <input> in the page. It then read the field's value back. The clipboard was set to PASTE-OK first. The same harness ran on main's mac.rs and on this branch, 3 times each:

main  run 1-3: menus=["", "View"]         paste= | undo= | redo= | selectall+copy+paste= | cut=CUT-OK | paste-after-cut=CUT-OK
fix   run 1-3: menus=["", "Edit", "View"] paste=PASTE-OK | undo= | redo=PASTE-OK | selectall+copy+paste=COPY-OK | cut= | paste-after-cut=CUT-OK

How to read it:

  • On main, nothing reaches the field: paste leaves it empty, and cut leaves the text in place.
  • With the fix, all six keys work:
    • paste;
    • undo of the paste;
    • redo;
    • ⌘A ⌘C, then paste into the emptied field;
    • ⌘X empties the field;
    • paste after the cut.

A second check selected a non-editable log line and pressed ⌘C. Pasting into the field gave LOG-LINE, so selected text still copies through the menu now that the page doesn't.

  • python3 scripts/ui-test.py: all pass, including the parity runs.
    • The updated logselect.js fails against main's index.html on macOS only (copies sent: got 1 want 0).
  • python3 scripts/i18n-check.py: PASS 1671 keys, 37 language file(s), 0 problem(s).
  • cargo test -p kiri --bin kiri lang:: passes.
  • cargo clippy -p kiri adds no warnings in the changed lines.

Tested on: macOS 27.0 (Apple silicon). Windows and Linux: page tests only, as above.

How you found it

  • I use Kiri and ran into this myself
  • I found it by reading the code or comparing with Docker
  • Someone else reported it (link the issue above)

AI tools used to write this change: yes. An AI coding assistant helped write and test it, including the translations. I reviewed and tested every change.

Checklist

  • I have at most 3 pull requests open on Kiri, this one included
  • cargo fmt, cargo clippy and the tests pass
  • It works on macOS, Windows and Linux, or the change only touches one of them

AndreKurait added a commit to AndreKurait/asagiri that referenced this pull request Nov 16, 2026
Port the remaining public page-handler change after Asagiri's native
Edit menu and translated menu labels were already integrated. Leave Mac
copy to the native menu while retaining Ctrl-C handling on Windows and
Linux and the terminal and text fields' own editing behavior.

The original page failed the new Mac duplicate-copy regression. All
nine headless clipboard cases across the three platforms and packaged
page assembly now pass. Native AppKit key dispatch remains a separate
runtime qualification.

Upstream-PR: libracoder/kiri#352
Upstream-Commit: d629da8bc64a85833feae3ae7e2c4e0d3f759fe7
Co-authored-by: Andre Kurait <akurait@amazon.com>
Signed-off-by: Andre Kurait <akurait@amazon.com>
@sayjeyhi

Copy link
Copy Markdown

I see copy/paste does not work in container terminal as well, will this be fixing that as well? @sundarshahi

@sundarshahi

Copy link
Copy Markdown
Author

Yes, on the Mac. A container's Terminal tab types commands into an ordinary text field, so it had the same cause: with no Edit menu, ⌘V, ⌘X, ⌘C and ⌘A in that field did nothing. With this PR they work there too.

I checked it on that tab's own field, pressing the keys through the app the way a keyboard does, on main and on this branch, 3 runs each:

                                   main        this PR
⌘V into the command field          nothing     pastes
⌘A then ⌘X                         nothing     cuts
⌘A ⌘C, clear, ⌘V                   nothing     pastes it back
⌘C on selected output              copies      copies

The terminal panel at the bottom of the window, the one with tabs and splits, handles ⌘C and ⌘V itself. Both already work there on main, and this PR doesn't change it.

If you still see it with this PR, could you say which system you're on and which of the two terminals it was? This PR only changes the Mac. On Windows and Linux, the WebView already handles Ctrl+C and Ctrl+V in text fields itself.

…er#340)

On the Mac, the editing keys reach a WKWebView's text fields through a
menu item's key equivalent. The menu bar had no Edit menu, so every one
of those keys beeped in Settings' fields. An Edit menu with the standard
items (undo:, redo:, cut:, copy:, paste:, selectAll:) sends them down the
responder chain to the page.

The page still sees each key first. Keys it handles itself (the
terminal's ⌘C and ⌘V, a list's ⌘A) are cancelled there and never reach
the menu. The page's own ⌘C for selected log text was there only because
the Edit menu was missing. On the Mac, Edit → Copy now does that job, so
the page no longer copies the text a second time. Windows and Linux are
unchanged, and the log-selection test runs on all three.
@libracoder

Copy link
Copy Markdown
Owner

@sundarshahi one addition before this goes in, please. The page sets user-select: none on body, and the global search field (.gfind input in index.html) doesn't turn it back on, so ⌘A and selection in that field may not work even with the Edit menu. Please add -webkit-user-select: text; user-select: text; to .gfind input, as the other inputs have. Credit to @eryajf, who spotted it in #397 (closed as a duplicate of this PR).

The window sets user-select: none on body, and .gfind input didn't turn it
back on. Credit to @eryajf, who spotted it in libracoder#397.
@sundarshahi

Copy link
Copy Markdown
Author

Done in 0394b09: .gfind input now has -webkit-user-select: text; user-select: text;, like the other inputs. Thanks @eryajf.

  • The Mac's window: with .gfind input as it is on main, the field still worked here. With real ⌘ key presses on macOS 27, ⌘A ⌘X, ⌘A ⌘C, ⌘V all worked in 4 of 4 runs. WebKit reports user-select: text for a text field whatever body says.
  • WebView2 and WebKitGTK: I couldn't check those by hand, so the rule is there for them, and it matches the other fields either way.
  • Guard: tests/ui/logselect.js checks that the search field's computed user-select is text on all three systems. It fails on all three without the line (got "none") and passes with it. The rest of scripts/ui-test.py passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unable to copy & paste anything from/to textfield in setting panel

3 participants