Skip to content

Add selectable markdown context menu builder#134

Open
momadvisor wants to merge 2 commits into
foresightmobile:mainfrom
momadvisor:add-selectable-context-menu-builder
Open

Add selectable markdown context menu builder#134
momadvisor wants to merge 2 commits into
foresightmobile:mainfrom
momadvisor:add-selectable-context-menu-builder

Conversation

@momadvisor

@momadvisor momadvisor commented Jun 30, 2026

Copy link
Copy Markdown

Summary

  • Adds a contextMenuBuilder parameter to Markdown and MarkdownBody.
  • Passes the builder through to the internal SelectableText.rich widgets when selectable is enabled.
  • Preserves the existing default Flutter selection toolbar behavior when the parameter is omitted.
  • Allows callers to set contextMenuBuilder: null to suppress the selectable text context menu.
  • Updates selectable markdown selection callbacks to pass TextSpan.toPlainText(), so callers receive the full selectable plain text even when markdown produces rich/nested spans.

Motivation

Apps embedding selectable markdown may already provide their own surrounding context menu. Without a way to customize or suppress the internal SelectableText context menu, right-click/long-touch behavior can conflict with the app-level menu.

Also, consumers that implement their own selection-related UI need reliable plain text from onSelectionChanged. For rich markdown spans, using only TextSpan.text can be null or incomplete, while toPlainText() reflects the rendered selectable text.

Tests

  • flutter test test/context_menu_builder_test.dart
  • flutter analyze

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