Skip to content

feat: right-click context menu in the editor#8

Merged
fredclausen merged 1 commit into
mainfrom
editor-context-menu
Jun 30, 2026
Merged

feat: right-click context menu in the editor#8
fredclausen merged 1 commit into
mainfrom
editor-context-menu

Conversation

@fredclausen

Copy link
Copy Markdown
Member

What

Adds a right-click context menu to the editor surface (the second of two context-menu PRs; the sidebar menus landed in #7).

egui's TextEdit ships no context menu of its own, so this adds one rather than replacing anything. Entries:

  • Cut, Copy (disabled when there is no selection), Paste, Select all
  • Find\u2026, Find and replace\u2026
  • Save

How

egui can write the clipboard but exposes no imperative read, which a menu-driven Paste needs. So the clipboard ops are imperative:

  • clipboard module \u2014 wraps arboard (already in the tree via eframe; now a pinned direct dep, default features off) for read and write, non-panicking and logging on failure.
  • edit_ops module \u2014 pure, char-indexed buffer splices (selected_text, delete_range, replace_range) that back cut/paste/select. Fully unit-tested, no egui or clipboard coupling.
  • After an edit the resulting caret is stored back into the live TextEdit state so the cursor follows the change; the editor is refocused.
  • A clipboard edit that mutates the buffer is folded into the existing changed-this-frame path, so it persists to the swap file and refreshes search matches exactly like a typed edit.
  • Find/replace and Save reuse the existing deferred actions.

Menu choices flow through a deferred EditorAction applied after the editor borrow ends, matching the established MenuAction / TreeAction pattern.

Verification

cargo fmt --check, cargo clippy --all-targets --all-features -D warnings, cargo test --all (113 pass, +12 new across edit_ops and app), and cargo machete all green in the Nix dev shell. Release build compiles.

The only Cargo.lock change is adding arboard to frext's dependency list \u2014 no new packages were resolved, since it was already present transitively.

Add a context menu to the editor surface, which egui's TextEdit does not
provide on its own. The menu offers Cut, Copy, Paste, and Select all
(Cut/Copy disabled with no selection), plus Find, Find and replace, and
Save.

Clipboard text edits are imperative rather than event-driven: egui can
write the clipboard but exposes no read, so a new clipboard module uses
arboard for both directions, and a new edit_ops module holds the pure,
char-indexed buffer splices (cut/paste/select) that back them. After an
edit the resulting caret is stored back into the live TextEdit state so
the cursor follows the change. A clipboard edit that mutates the buffer is
folded into the existing changed-this-frame handling so it persists and
refreshes search matches like a typed edit.

Menu choices are collected into a deferred EditorAction and applied after
the editor borrow ends, matching the existing MenuAction/TreeAction
pattern. Find/replace and Save reuse the existing actions.
@fredclausen
fredclausen enabled auto-merge June 30, 2026 14:38
@fredclausen
fredclausen merged commit 66a9758 into main Jun 30, 2026
3 checks passed
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.

1 participant