Skip to content

Missing contextMenuBuilder support in CodeField #315

Description

@yogitah-mecha

Problem

CodeField does not expose a way to customize the text selection context menu
(copy / select all / custom actions), unlike Flutter's TextField and
EditableText, which provide contextMenuBuilder.

This makes it impossible to:

  • Customize the selection toolbar
  • Add app-specific actions (Search, Format, Go to line, etc.)
  • Match platform behavior or design requirements

What works in TextField

TextField(
  contextMenuBuilder: (context, editableTextState) {
    return AdaptiveTextSelectionToolbar(
      anchors: editableTextState.contextMenuAnchors,
      children: const [
        SelectionOptions(),
      ],
    );
  },
)

Current CodeField API

CodeField(
  controller: _codeController,
  textStyle: const TextStyle(fontFamily: 'monospace'),
)

There is currently no way to pass a contextMenuBuilder or otherwise customize
the selection toolbar.

Request / Proposal

Expose a contextMenuBuilder (or equivalent) on CodeField, and forward it
internally to the underlying EditableText.

Example API:

CodeField(
  controller: _codeController,
  contextMenuBuilder: (context, editableTextState) {
    return AdaptiveTextSelectionToolbar(
      anchors: editableTextState.contextMenuAnchors,
      children: const [
        SelectionOptions(),
      ],
    );
  },
)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions