Add an editor context menu for selected text - #929
Conversation
|
Arham Amin (@arhxam) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
| && (pos.y != end.y || pos.x < end.x) | ||
| }) | ||
| { | ||
| self.textarea_context_menu_position = Some(mouse); |
There was a problem hiding this comment.
I like the idea of this PR overall, but this addition is not suistainable long-term. Eventually (and I mean: in the near-term) this would need to be rewritten as other features are added. A different approach is required that allows for capturing right-clicks.
I was actually thinking about this lately because I do not like how the input system works right now. I found AI somewhat unhelpful in my quest to find a different approach FYI. One idea I had was to model the input event API somewhat loosely around how browser key and mouse events work. The question is how to marry that with an immediate mode UI.
Fixes #854.
Summary
Right-clicking inside the current text selection now opens a small in-editor context menu with Cut, Copy, Paste, Select All, and Find. The menu reuses Edit's existing command, localization, clipboard, and TUI menu primitives, so the actions behave the same as their Edit-menu and keyboard-shortcut equivalents.
The popup follows the click position, flips toward the viewport when opened near the right or bottom edge, supports normal keyboard focus, and closes on Escape, command activation, or focus loss. Right-clicks outside a selection keep the existing behavior.
Test plan
cargo test -p edit --bin edit draw_editor::tests::right_clicking_selected_text_opens_context_menu -- --nocapturecargo test --workspacecargo fmt --all -- --checkcargo clippy --workspace --all-targets -- -D warningsThe regression test creates a real selection, delivers a right-mouse event through the TUI input path, and verifies the rendered popup contains each requested localized command.