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

SelectionArea does not copy the text sometimes #104549

Open
nilsreichardt opened this issue May 24, 2022 · 12 comments
Open

SelectionArea does not copy the text sometimes #104549

nilsreichardt opened this issue May 24, 2022 · 12 comments
Labels
f: selection SelectableRegion, SelectionArea, SelectionContainer, Selectable, and related APIs found in release: 3.1 Found to occur in 3.1 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list team-framework Owned by Framework team triaged-framework Triaged by Framework team

Comments

@nilsreichardt
Copy link
Contributor

I can confirm the comment by @justinmc:

Copy didn't work for me sometimes

In the example, if I click and drag to select some of the text but I start the gesture near the edge of the window outside of the Text widgets, then ctrl-c doesn't copy the selected text. The correct text is selected, and right clicking and using the menu to copy does work, but not ctrl-c.

#95226 (review)

Here is my screen recording.

Screen.Recording.2022-05-24.at.23.50.19.mov

I used CRTL + C to copy my text but it didn't work. I removed the ElevatedButton, used hot restart and it worked again. Adding the ElevatedButton, used hot restart and it worked again 🤔

I used the commit 577d6240dbcdbd3cd00e9b4a8c4564e70279f014 as Flutter SDK (the latest commit of @chunhtai branch inherited-selection).

My app
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// This example shows how to make a screen selectable..

import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      // You need to add the "SelectionArea" to make the text selectable.
      home: SelectionArea(
        child: Scaffold(
          body: Padding(
            padding: const EdgeInsets.all(16),
            child: Center(
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: <Widget>[
                  Text(
                    'Fast',
                    style: Theme.of(context).textTheme.titleLarge,
                  ),
                  const Text(
                    'Flutter code compiles to ARM or Intel machine code as well as JavaScript, for fast performance on any device.',
                  ),
                  ElevatedButton(
                    onPressed: () {},
                    child: const Text('Try it in DartPad'),
                  )
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}

@chunhtai Unfortunately, I don't have more information because I couldn't reproduce it anymore. But when I know more, I will post it here :)

@chunhtai chunhtai added framework flutter/packages/flutter repository. See also f: labels. f: selection SelectableRegion, SelectionArea, SelectionContainer, Selectable, and related APIs labels May 24, 2022
@chunhtai
Copy link
Contributor

is this Linux only? I can't seem to reproduce it in macOS

@nilsreichardt
Copy link
Contributor Author

I'm using a MacBook M1 with macOS 12.2.1 (21D62)

@chunhtai
Copy link
Contributor

just want to double check you meant cmd+c and not ctrl+c right?

For me it works correctly

@nilsreichardt
Copy link
Contributor Author

I used CMD + C 😅

@nilsreichardt
Copy link
Contributor Author

I tried 10 minutes to reproduce it again but unfortunately I wasn't able to achieve it. But I can definitely tell you that I had the issue. I discovered the issue when creating the video recording for #104548. After creating #104548, I created a video recording for this ticket.

@bharatmk256
Copy link

Right now I am trying to copy text on my Linux machine, but it's not working, right click and copy works but ctrl+c is not working

@nilsreichardt
Copy link
Contributor Author

When I remember correctly the same was for me. Right click and copy worked but cmd + c not. But I'm not 100% sure about this.

@maheshmnj maheshmnj changed the title SelecationArea does not copy the text sometimes SelectionArea does not copy the text sometimes May 25, 2022
@exaby73
Copy link
Member

exaby73 commented May 25, 2022

I was able to reproduce this issue on web running on MacOS. Though after the one time I did, I couldn't reproduce it again. Luckily, I took a video of the behavior I experienced which matches with @nilsreichardt.

Video
104549_web_master.mov
Code sample
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'Multiline text copy demo',
      home: HomePage(),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Multiline text copy demo')),
      body: SelectionArea(
        child: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(
                'This is a title',
                style: Theme.of(context).textTheme.headline6,
              ),
              const SizedBox(height: 20),
              const Text(
                'Lorem ipsum dolor sit amet, consectetur adipiscing elit. '
                'Fusce gravida sollicitudin.',
              ),
            ],
          ),
        ),
      ),
    );
  }
}
flutter doctor -v (Master)
[✓] Flutter (Channel master, 3.1.0-0.0.pre.897, on macOS 12.4 21F79 darwin-arm, locale en-US)
    • Flutter version 3.1.0-0.0.pre.897 at /Users/nabeelparkar/fvm/versions/master
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 680a8192b0 (2 hours ago), 2022-05-24 21:23:09 -0700
    • Engine revision 7274f79325
    • Dart version 2.18.0 (build 2.18.0-149.0.dev)
    • DevTools version 2.13.1

[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
    • Android SDK at /Users/nabeelparkar/Library/Android/sdk/
    • Platform android-32, build-tools 32.1.0-rc1
    • ANDROID_SDK_ROOT = /Users/nabeelparkar/Library/Android/sdk/
    • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 13.4)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • CHROME_EXECUTABLE = /Applications/Brave Browser.app/Contents/MacOS/Brave Browser

[✓] Android Studio (version 2021.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)

[✓] IntelliJ IDEA Ultimate Edition (version 2022.1.1)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin version 67.1.4
    • Dart plugin version 221.5591.58

[✓] VS Code (version 1.67.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.40.0

[✓] Connected device (3 available)
    • iPhone 13 Pro Max (mobile) • 16B8F156-111C-489F-A6E5-2D79142036B4 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-15-5 (simulator)
    • macOS (desktop)            • macos                                • darwin-arm64   • macOS 12.4 21F79 darwin-arm
    • Chrome (web)               • chrome                               • web-javascript • Brave Browser 101.1.38.119

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

@exaby73 exaby73 added has reproducible steps The issue has been confirmed reproducible and is ready to work on found in release: 3.1 Found to occur in 3.1 a: typography Text rendering, possibly libtxt and removed a: typography Text rendering, possibly libtxt labels May 25, 2022
@chunhtai
Copy link
Contributor

so everyone has the issue for the first time... I have a feeling there maybe some bug in the flutter tool or embedding. The copy uses the same mechanism TextFields are using, I wonder if similar issue happens to the TextField

@goderbauer goderbauer added the P2 Important issues not at the top of the work list label May 25, 2022
@Mr-1311
Copy link

Mr-1311 commented Feb 21, 2023

This issue still relevent but it happens with Text.rich widget with TextSpans.
please try this code:

import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: Scaffold(
          body: SelectionArea(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: const <Widget>[
            SelectionArea(
              child: Text.rich(
                TextSpan(
                  text: 'test span. ',
                  children: [
                    TextSpan(
                      text: 'another text span',
                    )
                  ],
                ),
              ),
            ),
            TextField(),
          ],
        ),
      )),
    );
  }
}

I've tested on windows and linux both debug and release builds, flutter version 3.7.1
ctrl-c doesn't work but right-click and copy works. Also double click to select word doesn't work.

@javiermrz
Copy link

javiermrz commented Aug 13, 2023

Any update on this? While on Chrome in Mac , I can't copy with keyboard shortcut (CMD + C), but I can copy by right clicking and pressing copy 🤔

@suysoftware
Copy link

Check here maybe you can find solution. #104548 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
f: selection SelectableRegion, SelectionArea, SelectionContainer, Selectable, and related APIs found in release: 3.1 Found to occur in 3.1 framework flutter/packages/flutter repository. See also f: labels. has reproducible steps The issue has been confirmed reproducible and is ready to work on P2 Important issues not at the top of the work list team-framework Owned by Framework team triaged-framework Triaged by Framework team
Projects
None yet
Development

No branches or pull requests

8 participants