Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to disable right click select on selectable text, but keep it selectable with left click #148045

Open
saibotma opened this issue May 9, 2024 · 1 comment
Labels
a: mouse Issues related to using a mouse or mouse support c: proposal A detailed proposal for a change to Flutter f: selection SelectableRegion, SelectionArea, SelectionContainer, Selectable, and related APIs framework flutter/packages/flutter repository. See also f: labels. P3 Issues that are less important to the Flutter project team-framework Owned by Framework team triaged-framework Triaged by Framework team

Comments

@saibotma
Copy link

saibotma commented May 9, 2024

Use case

Consider the following widget:

class MyScreen extends StatelessWidget {
  const MyScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: GestureDetector(
          onSecondaryTap: () => print("I was tapped. ${DateTime.now()}"),
          child: Container(
            padding: const EdgeInsets.all(32),
            color: Colors.red,
            child: Container(
              color: Colors.blue,
              child: const SelectableText(
                "I am selectable",
                contextMenuBuilder: null,
              ),
            ),
          ),
        ),
      ),
    );
  }
}

The user can select the selectable text with left click, and a right click on the red container prints "I was tapped". However, a right click on the selectable text selects the clicked on word instead of printing "I was tapped".

Screen.Recording.2024-05-09.at.11.40.09.mov

Setting enableInteractiveSelection to false makes the text un-selectable, but also ignores the right click.
Obviously, same behaviour when wrapping SelectableText in AbsorbPointer or IgnorePointer.

I also tried creating a custom AbsorbRightClickPointer widget, however as far as I can tell, it is not possible to get the pointer type in RenderBox.hitTest.

Without this it is not possible to implement for example a custom context menu, that opens both when right-clicking the red container and the text inside as it is done in Telegram Desktop:

Screen.Recording.2024-05-09.at.11.38.18.mov

Proposal

Make it possible to disable or adjust the right click behaviour of selectable text.

@danagbemava-nc danagbemava-nc added in triage Presently being triaged by the triage team framework flutter/packages/flutter repository. See also f: labels. c: proposal A detailed proposal for a change to Flutter a: mouse Issues related to using a mouse or mouse support f: selection SelectableRegion, SelectionArea, SelectionContainer, Selectable, and related APIs team-framework Owned by Framework team and removed in triage Presently being triaged by the triage team labels May 9, 2024
@goderbauer
Copy link
Member

cc @Renzo-Olivares

@goderbauer goderbauer added P3 Issues that are less important to the Flutter project triaged-framework Triaged by Framework team labels May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: mouse Issues related to using a mouse or mouse support c: proposal A detailed proposal for a change to Flutter f: selection SelectableRegion, SelectionArea, SelectionContainer, Selectable, and related APIs framework flutter/packages/flutter repository. See also f: labels. P3 Issues that are less important to the Flutter project team-framework Owned by Framework team triaged-framework Triaged by Framework team
Projects
None yet
Development

No branches or pull requests

3 participants