Skip to content

Missing contextMenuBuilder support in CodeField #315

@yogitah-mecha

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(),
      ],
    );
  },
)

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