Skip to content

feat(text): add default right-click menu for SelectableTextBlock (#211) - #217

Merged
239573049 merged 1 commit into
mainfrom
feat/selectable-text-context-menu-211
Nov 26, 2026
Merged

239573049 merged 1 commit into
mainfrom
feat/selectable-text-context-menu-211

Conversation

@239573049

Copy link
Copy Markdown
Member

Fixes #211

Summary

  • Extends TextContextMenu to Avalonia.Controls.SelectableTextBlock (covering form/display selectable labels, DecoratedTextBlock, and CodeBlock), registered idempotently when UseArcControls() commits.
  • Opens the localized Arc MenuSurface (en-US / zh-CN / zh-TW) with Copy and Select all on right-click, ContextMenu key, or Shift+F10.
  • Preserves the user's selection when focus moves into MenuSurface (since Avalonia 12.2's SelectableTextBlock.OnLostFocus clears selection when Avalonia's own ContextMenu/ContextFlyout is not open) and clears the restored selection if the menu closes without returning focus to the block.
  • Respects e.Handled, inherited TextContextMenu.IsEnabled, and app-set ContextMenu / ContextFlyout / arc:ContextMenu.Menu. No new public API added.

Verification

  • dotnet build src/TKCode.Arc -c Debug (net8.0 / net10.0 / net11.0): 0 warnings, 0 errors.
  • dotnet test tests/TKCode.Arc.Tests --filter "FullyQualifiedName~TextContextMenuTests|FullyQualifiedName~CodeBlockTests|FullyQualifiedName~BaseThemeInventoryTests": 34 passed, 0 failed.

- Register an idempotent ContextRequested class handler for SelectableTextBlock in TextContextMenu, invoked via ArcBuilderExtensions.UseArcControls().
- Show Copy and Select all via MenuSurface using TextContextMenuLangResources (en-US / zh-CN / zh-TW), supporting both Text and Inlines, DecoratedTextBlock and CodeBlock.
- Preserve selection when focus moves into MenuSurface (working around SelectableTextBlock.OnLostFocus clearing selection when Avalonia's own ContextMenu/ContextFlyout is not open) and clear restored selection if closed without returning focus.
- Respect e.Handled, inherited TextContextMenu.IsEnabled, and app-set ContextMenu / ContextFlyout / arc:ContextMenu.Menu.
- Add headless unit tests covering pointer/keyboard open, clipboard copy, SelectAll, Inlines, empty text, opt-out/custom menus, language switching, and CodeBlock/DecoratedTextBlock.
@239573049
239573049 merged commit dbdec3b into main Nov 26, 2026
28 checks passed
@239573049
239573049 deleted the feat/selectable-text-context-menu-211 branch November 26, 2026 18:32
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