Skip to content

Editor: built-in editing context menu#153

Merged
tig merged 9 commits into
developfrom
copilot/add-default-context-menu-to-editor
May 17, 2026
Merged

Editor: built-in editing context menu#153
tig merged 9 commits into
developfrom
copilot/add-default-context-menu-to-editor

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 17, 2026

Editor had no built-in context menu — consumers had to wire their own PopoverMenu and keep it in sync with ReadOnly/selection/undo state. TextView ships one by default; Editor should too.

Changes

  • Editor.ContextMenu.cs — new partial with:

    • ContextMenu property (nullable, settable, uses field keyword) — defaults to a PopoverMenu with Undo, Redo, Cut, Copy, Paste, Select All
    • Items use TG's declarative MenuItem(targetView, Command) constructor — the framework resolves title/help text from GlobalResources and routes commands to the Editor via command bubbling (no manual Action delegates)
    • State-aware item enablement on each show: mutating items disabled when ReadOnly, Cut/Copy disabled without selection, Undo/Redo reflect stack. Unknown commands from custom menus are left untouched so caller-set Enabled states are preserved.
    • Set to null to suppress; assign a custom PopoverMenu to replace
  • Editor.Mouse.cs — right-click routes to ShowContextMenu(screenPosition); returns false when ContextMenu is null so the click bubbles to parent views

  • Editor.Commands.csCommand.Context binding added; returns false when ContextMenu is null so the command bubbles to parent/application-level handlers

  • examples/ted — removed manual context menu wiring; ted's Edit menu bar items now also use declarative MenuItem(Editor, Command.X) binding, removing the manual Undo()/Redo()/SelectAll() wrapper methods

// Suppress the default menu
editor.ContextMenu = null;

// Or replace with a custom one
editor.ContextMenu = new PopoverMenu(myCustomItems);

Tests

9 integration tests covering: menu appears on right-click, null suppresses it, ReadOnly disables mutating items, no-selection disables Cut/Copy, Undo enabled after edit, default is non-null, declarative binding with command order verification, command routing for SelectAll and Undo. All 461 unit + 231 integration tests pass.

Copilot AI assigned Copilot and tig May 17, 2026
Copilot AI linked an issue May 17, 2026 that may be closed by this pull request
6 tasks
- Add Editor.ContextMenu property with default PopoverMenu (Undo, Redo,
  Cut, Copy, Paste, Select All)
- Handle right-click in Editor.Mouse.cs to show context menu
- Add Command.Context command binding
- State-aware: disable items based on ReadOnly, selection, undo/redo state
- Opt-out: set ContextMenu to null to suppress
- Update ted to use built-in context menu instead of custom wiring
- Add EditorContextMenuTests with 6 integration tests

Agent-Logs-Url: https://github.com/gui-cs/Editor/sessions/2b9401e3-9b8e-48ef-a1da-52daeb0e6be1

Co-authored-by: tig <585482+tig@users.noreply.github.com>
Copilot AI changed the title [WIP] Add default context menu to editor with basic commands Editor: built-in editing context menu May 17, 2026
Copilot finished work on behalf of tig May 17, 2026 14:34
Copilot AI requested a review from tig May 17, 2026 14:34
@tig tig marked this pull request as ready for review May 17, 2026 15:44
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: de26290d05

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/Terminal.Gui.Editor/Editor.Mouse.cs
@tig
Copy link
Copy Markdown
Member

tig commented May 17, 2026

@copilot In ted none of the context menu items appear to work. And same for the edit menu items on the ted menubar. Keyboard shortcuts are working.

MenuItem.Command alone does not route to PopoverMenu.Target on click —
the Action delegate is what fires. Added Action = () => InvokeCommand(...)
to all built-in context menu items, and also to ted's Edit menu bar
Cut/Copy/Paste items which were missing Action delegates.

Agent-Logs-Url: https://github.com/gui-cs/Editor/sessions/39672643-45b8-4619-9cf7-d1f709c3f83d

Co-authored-by: tig <585482+tig@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 17, 2026

@copilot In ted none of the context menu items appear to work. And same for the edit menu items on the ted menubar. Keyboard shortcuts are working.

Fixed in 60312bc. The issue was that MenuItem.Command alone doesn't route to PopoverMenu.Target on click — MenuItem.Action is what actually fires when the user clicks. Added Action = () => InvokeCommand(Command.X) to all built-in context menu items. Also added the same fix to ted's Edit menu bar Cut/Copy/Paste items which had the same issue (they only had Command set, no Action).

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.jetbrains.com
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/.nuget/packages/jetbrains.resharper.globaltools/2026.1.1/tools/net8.0/any/cleanupcode.unix.runtimeconfig.json /home/REDACTED/.nuget/packages/jetbrains.resharper.globaltools/2026.1.1/tools/net8.0/any/cleanupcode.exe Terminal.Gui.Editor.slnx --include=src/Terminal.Gui.Editor/Editor.ContextMenu.cs;examples/ted/TedApp.EditCommands.cs;tests/Terminal.Gui.Editor.IntegrationTests/EditorContextMenuTests.cs (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of tig May 17, 2026 16:18
@tig
Copy link
Copy Markdown
Member

tig commented May 17, 2026

@copilot read Claude.md and ensure you are following it in this pr.

Read TGs command.md.

Understand how bubbling works and utilize it.

…and routing

Replace manual Action delegates with declarative command binding per TG's
command.md. MenuItem(this, Command.X) lets the framework resolve title,
help text, and route the command to the Editor via bubbling — no explicit
Action callbacks needed.

- Editor.ContextMenu.cs: use field keyword, declarative MenuItem ctors
- TedApp.EditCommands.cs: declarative MenuItem(Editor, Command.X),
  remove Undo/Redo/SelectAll wrapper methods
- Tests: verify TargetView binding and command routing

Agent-Logs-Url: https://github.com/gui-cs/Editor/sessions/02daf29a-7174-4e18-8f56-9b737d56146a

Co-authored-by: tig <585482+tig@users.noreply.github.com>
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 17, 2026

@copilot read Claude.md and ensure you are following it in this pr.

Read TGs command.md. ...

Refactored in 5944e53 and 121f58f. Both the context menu and ted's Edit menu now use TG's declarative new MenuItem(targetView, Command.X) constructor — the framework resolves title/help text from GlobalResources and routes commands to the Editor via command bubbling. All manual Action delegates and wrapper methods (Undo(), Redo(), SelectAll()) removed. Also switched the ContextMenu property to use the field keyword per CLAUDE.md.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • www.jetbrains.com
    • Triggering command: /usr/share/dotnet/dotnet /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/.nuget/packages/jetbrains.resharper.globaltools/2026.1.1/tools/net8.0/any/cleanupcode.unix.runtimeconfig.json /home/REDACTED/.nuget/packages/jetbrains.resharper.globaltools/2026.1.1/tools/net8.0/any/cleanupcode.exe Terminal.Gui.Editor.slnx --include=src/Terminal.Gui.Editor/Editor.ContextMenu.cs;examples/ted/TedApp.EditCommands.cs;tests/Terminal.Gui.Editor.IntegrationTests/EditorContextMenuTests.cs (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of tig May 17, 2026 16:33
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 15fc560e71

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/Terminal.Gui.Editor/Editor.Commands.cs
Comment thread src/Terminal.Gui.Editor/Editor.ContextMenu.cs Outdated
@tig
Copy link
Copy Markdown
Member

tig commented May 17, 2026

@copilot resolve the merge conflicts in this pull request. And address cr feedback.

- Merge overwrite mode commands from develop into Editor.Commands.cs
- CR fix: right-click returns false when ContextMenu is null (allows bubbling)
- CR fix: Command.Context returns false when ContextMenu is null (allows bubbling)
- CR fix: UpdateContextMenuState skips unknown menu items (preserves custom enabled states)

Co-authored-by: tig <585482+tig@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 17, 2026

@copilot resolve the merge conflicts in this pull request. And address cr feedback.

Merge conflicts resolved and CR feedback addressed in b873112:

  • Merged overwrite mode commands from develop into Editor.Commands.cs
  • Right-click now returns false when ContextMenu is null, allowing the event to bubble to parent views
  • Command.Context handler returns false when menu is suppressed, enabling keyboard context-menu invocations to bubble
  • UpdateContextMenuState now skips unknown menu items instead of forcing them to true, preserving custom enabled states on caller-supplied menus

All 461 unit + 231 integration tests pass.

Copilot finished work on behalf of tig May 17, 2026 18:47
@tig tig merged commit de5bcfc into develop May 17, 2026
8 checks passed
@tig tig deleted the copilot/add-default-context-menu-to-editor branch May 17, 2026 20:54
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.

Editor: built-in editing context menu

2 participants