Skip to content

Incorrect selection move by word with Chinese script #106472

Closed

Description

@tgucio

Steps to Reproduce

  1. Execute flutter run on the code sample
  2. Copy and paste Chinese text
  3. Move to the beginning of the text
  4. Move the selection right by word (e.g. Ctrl + right arrow) twice, then left twice, then keep repeating

Expected results: Text selection goes back to the beginning

Actual results: Text selection keeps moving to the right

move-by-word

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 MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(primarySwatch: Colors.blue),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text(widget.title)),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: const <Widget>[
            Text('Type stuff below'),
            Expanded(
              child: TextField(maxLines: null),
            ),
          ],
        ),
      ),
    );
  }
}
Logs
> flutter doctor -v
[√] Flutter (Channel master, 3.1.0-0.0.pre.1354, on Microsoft Windows [Version 10.0.19044.1708], locale en-US)
    • Flutter version 3.1.0-0.0.pre.1354 on channel master at C:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision a30012b275 (9 hours ago), 2022-06-22 17:04:07 -0700
    • Engine revision fc08bf45b0
    • Dart version 2.18.0 (build 2.18.0-216.0.dev)
    • DevTools version 2.14.0

[X] Android toolchain - develop for Android devices
    X Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.


[√] Chrome - develop for the web
    • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

[√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.15)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.11.32510.428
    • Windows 10 SDK version 10.0.19041.0

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).

[√] VS Code, 64-bit edition (version 1.68.1)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 3.42.0

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19044.1708]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 102.0.5005.115
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 101.0.1210.39

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

! Doctor found issues in 2 categories.

Activity

  1. added
    in triagePresently being triaged by the triage team
    on Jun 24, 2022
  2. huycozy commented on Jun 24, 2022

    @huycozy
    Member

    Hi @tgucio, thanks for filing the issue.
    This issue is reproducible on the latest stable and master channels.
    When using Ctrl + right arrow, the cursor position is moved wrong, it always moves forward.

    Demo
    bandicam.2022-06-24.15-29-42-379.mp4
    Sample code
    import 'package:flutter/material.dart';
    
    void main() {
      runApp( MyApp());
    }
    
    class MyApp extends StatelessWidget {
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(primarySwatch: Colors.blue),
          home:  MyHomePage(),
        );
      }
    }
    
    class MyHomePage extends StatefulWidget {
    
      @override
      State<MyHomePage> createState() => _MyHomePageState();
    }
    
    class _MyHomePageState extends State<MyHomePage> {
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          body: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: const <Widget>[
                Text('Type stuff below'),
                Expanded(
                  child: TextField(maxLines: null),
                ),
              ],
            ),
          ),
        );
      }
    }
    flutter doctor -v
    [√] Flutter (Channel stable, 3.0.3, on Microsoft Windows [Version 10.0.19043.1766], locale en-US)
        • Flutter version 3.0.3 at C:\WIP\flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 676cefaaff (2 days ago), 2022-06-22 11:34:49 -0700
        • Engine revision ffe7b86a1e
        • Dart version 2.17.5
        • DevTools version 2.12.2
    
    Checking Android licenses is taking an unexpectedly long time...[√] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
        • Android SDK at C:\AndroidSDK
        • Platform android-32, build-tools 32.0.0
        • ANDROID_HOME = C:\AndroidSDK
        • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
        • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
        • All Android licenses accepted.
    
    [√] Chrome - develop for the web
        • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
    
    [√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.1.6)
        • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
        • Visual Studio Community 2022 version 17.1.32421.90
        • Windows 10 SDK version 10.0.20348.0
    
    [√] Android Studio (version 2021.2)
        • Android Studio at C:\Program Files\Android\Android Studio
        • 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+7-b1504.28-7817840)
    
    [√] VS Code (version 1.68.1)
        • VS Code at C:\Users\ADMIN\AppData\Local\Programs\Microsoft VS Code
        • Flutter extension version 3.42.0
    
    [√] Connected device (3 available)
        • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19043.1766]
        • Chrome (web)      • chrome  • web-javascript • Google Chrome 102.0.5005.115
        • Edge (web)        • edge    • web-javascript • Microsoft Edge 101.0.1210.53
    
    [√] HTTP Host Availability
        • All required HTTP hosts are available
    
    • No issues found!
    [√] Flutter (Channel master, 3.1.0-0.0.pre.1360, on Microsoft Windows [Version 10.0.19043.1766], locale en-US)
        • Flutter version 3.1.0-0.0.pre.1360 on channel master at C:\WIP\flutter_master
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 6c3a0e4d21 (4 hours ago), 2022-06-24 00:19:06 -0400
        • Engine revision fc08bf45b0
        • Dart version 2.18.0 (build 2.18.0-216.0.dev)
        • DevTools version 2.14.0
    
    Checking Android licenses is taking an unexpectedly long time...[√] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
        • Android SDK at C:\AndroidSDK
        • Platform android-32, build-tools 32.0.0
        • ANDROID_HOME = C:\AndroidSDK
        • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
        • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
        • All Android licenses accepted.
    
    [√] Chrome - develop for the web
        • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
    
    [√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.1.6)
        • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
        • Visual Studio Community 2022 version 17.1.32421.90
        • Windows 10 SDK version 10.0.20348.0
    
    [√] Android Studio (version 2021.2)
        • Android Studio at C:\Program Files\Android\Android Studio
        • 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+7-b1504.28-7817840)
    
    [√] VS Code (version 1.68.1)
        • VS Code at C:\Users\ADMIN\AppData\Local\Programs\Microsoft VS Code
        • Flutter extension version 3.42.0
    
    [√] Connected device (3 available)
        • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19043.1766]
        • Chrome (web)      • chrome  • web-javascript • Google Chrome 102.0.5005.115
        • Edge (web)        • edge    • web-javascript • Microsoft Edge 101.0.1210.53
    
    [√] HTTP Host Availability
        • All required HTTP hosts are available
    
    • No issues found!
  3. added
    a: text inputEntering text in a text field or keyboard related problems
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    a: internationalizationSupporting other languages or locales. (aka i18n)
    platform-windowsBuilding on or for Windows specifically
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    and removed
    in triagePresently being triaged by the triage team
    on Jun 24, 2022
  4. tgucio commented on Jun 24, 2022

    @tgucio
    ContributorAuthor

    Thanks for confirming @huycozy. BTW, I believe this isn't specific to windows but will behave the same on every platform (including mobile) using a HW keyboard.

  5. huycozy commented on Jun 28, 2022

    @huycozy
    Member

    @tgucio Thank you for reminding me, I can reproduce this issue on other desktop platforms. But it works well on Web.
    Providing demo video as below:

    • MacOS: ❌
    • Linux (Ubuntu): ❌
    • Web: ✅

    ✅: No Issue ❌: Issue reproduced

    Demo
    • MacOS:
    macos.mp4
    • Web:
    web.mp4
    • Linux (Ubuntu):
    linux.mp4
  6. gspencergoog commented on Jun 30, 2022

    @gspencergoog
    Contributor
  7. added
    P2Important issues not at the top of the work list
    on Jun 30, 2022
  8. justinmc commented on Jan 20, 2023

    @justinmc
    Contributor

    This appears fixed to me, can anyone else reproduce it on master still? It moves one character at a time now:

    Screencast.from.2023-01-20.15-48-00.webm

    Actually though, if I try it on gedit on Linux, it moves until it reaches punctuation. Maybe we should match that behavior.

    Screencast.from.2023-01-20.15-49-10.webm

    @Renzo-Olivares Do you have any thoughts on this since you have been working on boundary related stuff?

  9. gnprice commented on Mar 12, 2023

    @gnprice
    Member

    I don't reproduce the issue either. I think it would make sense to close it, and use a new issue for further improvements.

    Actually though, if I try it on gedit on Linux, it moves until it reaches punctuation. Maybe we should match that behavior.

    I think that behavior isn't great — it's moving past entire long clauses. But it might be better than moving a character at a time, given that if you want a character at a time you can always use plain left/right without Ctrl.

    The ideal behavior would be to segment the text into words and move a word at a time. This is typically 2-3 characters, but can be less or more. To make it easy for everyone to reproduce the same details, here's some copy-pasteable text (from a Wikipedia article):

    1894年,孫文成立興中會。1895年,興中會發動乙未廣州起義。1905年,中國同盟會在日本东京組成,孫被推為总理;確定「驅除韃虜,恢復中华,建立民國,平均地權」的革命政綱,提出三民主義學說;創辦《民報》,宣傳革命,同當時的中國改良派激烈論戰。

    In that first sentence, if I use Ctrl+right/left in a browser's text input (in Chrome on Linux), the pieces it moves past are:

    1894
    年
    ,
    孫文
    成立
    興中會
    。

    Each of those is a meaningful word or name (except the two that are pieces of punctuation.)

    Doing that well requires a nontrivial language model, which I imagine is why gedit hasn't done it. I don't know if SkParagraph or another subsystem we already use might be equipped to do that for us.

  10. justinmc commented on Mar 20, 2023

    @justinmc
    Contributor

    Thanks for the investigation, I've opened #123065 to track. I'll go ahead and close this one.

  11. github-actions commented on Apr 3, 2023

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  12. locked as resolved and limited conversation to collaborators on Apr 3, 2023
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

    P2Important issues not at the top of the work lista: desktopRunning on desktopa: internationalizationSupporting other languages or locales. (aka i18n)a: text inputEntering text in a text field or keyboard related problemsfound in release: 3.0Found to occur in 3.0found in release: 3.1Found to occur in 3.1frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packages

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions