Skip to content

mixin_markdown_widget: rework the right-click context menu - #551

Merged
boyan01 merged 1 commit into
mixin_markdown_widget/cjk-word-segmenterfrom
mixin_markdown_widget/context-menu
Oct 21, 2026
Merged

boyan01 merged 1 commit into
mixin_markdown_widget/cjk-word-segmenterfrom
mixin_markdown_widget/context-menu

Conversation

@boyan01

@boyan01 boyan01 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Stacked on #550. The right-click menu ignored where you clicked, always showed the same items, and stayed open on scroll and Escape. The menu now lives in MarkdownSelectionHost, so MarkdownWidget and MixinSelectionArea behave the same.

 on(secondary pointer down)
+  if contextMenuBuilder == null → return            # no menu, selection untouched
+  if pointer is inside the selection → keep it
+  else if macOS / iOS → select the word under the pointer
+  else → clear the selection
   show menu
-    Copy                                             # even with nothing selected
+    Copy        if text is selected
+    Copy link   if the pointer is over a link       # from the block model, incl. emphasis / table cells
     Select all
     Copy all    if enabled
-    Clear selection
+  hide on Escape, scroll (ancestor or descendant), any click, or after a button

Breaking API:

-typedef MarkdownContextMenuBuilder = Widget Function(
-  BuildContext, MarkdownSelectionController, List<ContextMenuButtonItem>, TextSelectionToolbarAnchors);
+typedef MarkdownContextMenuBuilder = Widget Function(BuildContext, MarkdownContextMenuDetails);
+// details: anchors, buttonItems (defaults, each closes the menu), selectionController, linkDestination, hide()
-contextMenuBuilder: null            # meant "use MarkdownContextMenu"
+contextMenuBuilder: defaultMarkdownContextMenuBuilder   # null now means no menu
-MarkdownContextMenu                 # removed
 showCopyAllInContextMenu            # @Deprecated: filter details.buttonItems instead

flutter-app's contextMenuBuilder: (_, _, _, _) => SizedBox.shrink() becomes contextMenuBuilder: null. Version and CHANGELOG are left for the release (0.4.0).

Evidence

Before: the new markdown_context_menu_test.dart (the 6 behavior tests) against the old lib/, 5 failed:

macOS right click selects the word under the pointer   Expected: 'brave'  Actual: ''
Windows right click outside the selection clears it    Expected: ''       Actual: 'brave'
applies inside MixinSelectionArea                      Expected: 'brave'  Actual: ''
Escape closes the menu and keeps the selection         menu still shown
scrolling closes the menu                              menu still shown

After: 13/13, including the new API: Copy writes the selection, Copy link writes the destination for a plain link, an emphasized link, and a link in a table cell, no Copy link on plain text, a null builder shows nothing and keeps the selection, a custom builder receives the details and closes the menu with details.hide.

Package flutter test on macOS: 280 passed. flutter analyze (package and example): no issues. Checked by hand in the macOS example: right click word selection (incl. Chinese), Copy link on plain / emphasized / table links, closing on Escape, scroll, click, and button press, and the custom item. Windows and Linux not checked in the GUI.

Merge Danger

Door: two-way

Blast Radius: consumers

Callers that pass a 4-argument contextMenuBuilder or use MarkdownContextMenu stop compiling. Callers that pass contextMenuBuilder: null to get the default menu now get no menu. Right click on Windows/Linux outside the selection now clears it.

Right clicking keeps a selection under the pointer. Elsewhere, macOS and
iOS select the word under the pointer and other platforms clear the
selection. The default menu shows Copy only when text is selected, Copy
link over a link, Select all, and Copy all; Clear selection is gone. It
closes on Escape, scrolling, and any click. MarkdownWidget and
MixinSelectionArea share this logic in MarkdownSelectionHost.

BREAKING CHANGE: MarkdownContextMenuBuilder is now
(BuildContext, MarkdownContextMenuDetails). The details carry the
anchors, the default button items, the selection controller, the link
under the pointer, and hide(). contextMenuBuilder defaults to
defaultMarkdownContextMenuBuilder; pass null to show no menu.
MarkdownContextMenu is removed, and showCopyAllInContextMenu is
deprecated in favor of filtering details.buttonItems.
@boyan01
boyan01 added this pull request to stack #545 October 21, 2026 01:38
@boyan01
boyan01 marked this pull request as ready for review October 21, 2026 01:49
@boyan01
boyan01 merged commit 31a0cbc into main Oct 21, 2026
7 checks passed
@boyan01
boyan01 deleted the mixin_markdown_widget/context-menu branch October 21, 2026 01:49
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