Skip to content

Incorrect horizontal caret movement with Unicode combining characters #98516

Closed

Description

@tgucio

Steps to Reproduce

  1. Execute flutter run on the code sample (just a text field)

  2. Paste "Zalgo" unicode combining characters abuse string to the text field: Zalgo

Expected results: Can move the caret between all character using keyboard left/right arrows

Actual results: Caret is stuck before the first character on first right arrow keypress, then jumps over two characters.

Interestingly when selecting text using Shift + right arrow the issue isn't there.

Code sample
import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: 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({Key? key, required this.title}) : super(key: key);

  final String title;

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

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() { _counter++; });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text(widget.title)),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text('You have pushed the button this many times:'),
            Text(
              '$_counter',
              style: Theme.of(context).textTheme.headline4,
            ),
            const Expanded(
              child: TextField(maxLines: null),
            ),
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}
Logs
 flutter doctor -v
[√] Flutter (Channel master, 2.11.0-0.0.pre.562, on Microsoft Windows [Version 10.0.19044.1526], locale en-US)
    • Flutter version 2.11.0-0.0.pre.562 at C:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2a2f973120 (2 hours ago), 2022-02-15 07:33:57 -0800
    • Engine revision e683e0cd3b
    • Dart version 2.17.0 (build 2.17.0-105.0.dev)
    • DevTools version 2.10.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.8)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.11.32002.261
    • 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.64.2)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 3.34.0

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

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

! Doctor found issues in 2 categories.

Activity

  1. changed the title [-]Incorrect caret jump in Zalgo test[/-] [+]Incorrect horizontal caret movement in Zalgo test[/+] on Feb 15, 2022
  2. changed the title [-]Incorrect horizontal caret movement in Zalgo test[/-] [+]Incorrect horizontal caret movement with Unicode combining characters[/+] on Feb 15, 2022
  3. maheshj01 commented on Feb 16, 2022

    @maheshj01
    Member

    Hi @tgucio, Thanks for filing the issue. I am able to reproduce the issue on the master channel and it works fine on the stable channel. On the master channel, The first two characters are skipped when pressing the arrow keys

    macOS output

    master ❌ stable ✅
    Screen.Recording.2022-02-16.at.4.15.57.PM.mov
    Screen.Recording.2022-02-16.at.4.33.34.PM.mov

    Windows output

    master ❌ stable ✅
    warnings.2022-02-16.10-38-05_Trim.mp4
    warnings.2022-02-16.10-30-54_Trim.mp4
    flutter doctor -v (macOS)
    [✓] Flutter (Channel stable, 2.10.1, on macOS 12.1 21C52 darwin-arm, locale en-GB)
        • Flutter version 2.10.1 at /Users/mahesh/Documents/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision db747aa133 (7 days ago), 2022-02-09 13:57:35 -0600
        • Engine revision ab46186b24
        • Dart version 2.16.1
        • DevTools version 2.9.2
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
        • Android SDK at /Users/mahesh/Library/Android/sdk
        • Platform android-31, build-tools 31.0.0
        • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • CocoaPods version 1.10.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 4.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.8+10-b944.6916264)
    
    [✓] IntelliJ IDEA Community Edition (version 2021.2.1)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 61.2.4
        • Dart plugin version 212.5080.8
    
    [✓] VS Code (version 1.63.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.34.0
    
    [✓] Connected device (3 available)
        • Redmi K20 Pro (mobile) • 192.168.1.2:5555 • android-arm64  • Android 11 (API 30)
        • macOS (desktop)        • macos            • darwin-arm64   • macOS 12.1 21C52 darwin-arm
        • Chrome (web)           • chrome           • web-javascript • Google Chrome 98.0.4758.102
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    • No issues found!
    
    [✓] Flutter (Channel master, 2.11.0-0.0.pre.555, on macOS 12.1 21C52 darwin-arm, locale en-GB)
        • Flutter version 2.11.0-0.0.pre.555 at /Users/mahesh/Documents/flutter_master
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 06bf6a128d (30 hours ago), 2022-02-14 23:30:18 -0500
        • Engine revision 20bd78ca3e
        • Dart version 2.17.0 (build 2.17.0-105.0.dev)
        • DevTools version 2.10.0
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
        • Android SDK at /Users/mahesh/Library/Android/sdk
        • Platform android-31, build-tools 31.0.0
        • ANDROID_HOME = /Users/mahesh/Library/Android/sdk
        • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
        • Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1)
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • CocoaPods version 1.10.2
    
    [✓] Chrome - develop for the web
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Android Studio (version 4.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.8+10-b944.6916264)
    
    [✓] IntelliJ IDEA Community Edition (version 2021.2.1)
        • IntelliJ at /Applications/IntelliJ IDEA CE.app
        • Flutter plugin version 61.2.4
        • Dart plugin version 212.5080.8
    
    [✓] VS Code (version 1.63.2)
        • VS Code at /Applications/Visual Studio Code.app/Contents
        • Flutter extension version 3.34.0
    
    [✓] Connected device (3 available)
        • Redmi K20 Pro (mobile) • 192.168.1.2:5555 • android-arm64  • Android 11 (API 30)
        • macOS (desktop)        • macos            • darwin-arm64   • macOS 12.1 21C52 darwin-arm
        • Chrome (web)           • chrome           • web-javascript • Google Chrome 98.0.4758.102
    
    [✓] HTTP Host Availability
        • All required HTTP hosts are available
    
    • No issues found!
    
    flutter doctor -v (windows)
    [√] Flutter (Channel stable, 2.10.1, on Microsoft Windows [Version 10.0.19044.1526], locale en-US)
        • Flutter version 2.10.1 at C:\flutter_sdk\stable
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision db747aa133 (6 days ago), 2022-02-09 13:57:35 -0600
        • Engine revision ab46186b24
        • Dart version 2.16.1
        • DevTools version 2.9.2
    
    [√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
        • Android SDK at C:\Users\mahesh\AppData\Local\Android\sdk
        • Platform android-31, build-tools 31.0.0
        • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
        • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)
        • All Android licenses accepted.
    
    [√] Chrome - develop for the web
        • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
    
    [√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.4)
        • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
        • Visual Studio Community 2019 version 16.11.31727.386
        • Windows 10 SDK version 10.0.19041.0
    
    [√] Android Studio (version 2020.3)
        • 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.10+0-b96-7249189)
    
    [√] VS Code (version 1.64.2)
        • VS Code at C:\Users\mahesh\AppData\Local\Programs\Microsoft VS Code
        • Flutter extension version 3.34.0
    
    [√] Connected device (3 available)
        • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.19044.1526]
        • Chrome (web)      • chrome  • web-javascript • Google Chrome 98.0.4758.102
        • Edge (web)        • edge    • web-javascript • Microsoft Edge 97.0.1072.76
    
    [√] HTTP Host Availability
        • All required HTTP hosts are available
    
    • No issues found!
    
    [√] Flutter (Channel master, 2.11.0-0.0.pre.554, on Microsoft Windows [Version 10.0.19044.1526], locale en-US)
        • Flutter version 2.11.0-0.0.pre.554 at C:\flutter_sdk\master
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 894ef49c7c (26 hours ago), 2022-02-14 22:15:17 -0500
        • Engine revision 8714a2448f
        • Dart version 2.17.0 (build 2.17.0-105.0.dev)
        • DevTools version 2.10.0
    
    [√] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
        • Android SDK at C:\Users\mahesh\AppData\Local\Android\sdk
        • Platform android-31, build-tools 31.0.0
        • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java      
        • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189)    
        • All Android licenses accepted.
    
    [√] Chrome - develop for the web
        • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
    
    [√] Visual Studio - develop for Windows (Visual Studio Community 2019 16.11.4)      
        • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
        • Visual Studio Community 2019 version 16.11.31727.386
        • Windows 10 SDK version 10.0.19041.0
    
    [√] Android Studio (version 2020.3)
        • 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.10+0-b96-7249189)        
    
    [√] VS Code (version 1.64.2)
        • VS Code at C:\Users\mahesh\AppData\Local\Programs\Microsoft VS Code
        • Flutter extension version 3.34.0
    
    [√] Connected device (4 available)
        • Windows (desktop)       • windows • windows-x64     • Microsoft Windows [Version 10.0.19044.1526]
        • Windows (UWP) (desktop) • winuwp  • windows-uwp-x64 • 
        • Chrome (web)            • chrome  • web-javascript  • Google Chrome 98.0.4758.102
        • Edge (web)              • edge    • web-javascript  • Microsoft Edge 97.0.1072.76
    
    [√] HTTP Host Availability
        • All required HTTP hosts are available
    
    • No issues found!
    

    ✅ : No Issue
    ❌: Issue reproduced

    Labeling the issue as a regression

  4. added
    a: text inputEntering text in a text field or keyboard related problems
    engineflutter/engine related. See also e: labels.
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    p: material_uimaterial_ui package in flutter/packages
    c: regressionIt was better in the past than it is now
    and removed
    in triagePresently being triaged by the triage team
    on Feb 16, 2022
  5. tgucio commented on Feb 17, 2022

    @tgucio
    ContributorAuthor

    Great, thanks for capturing the videos - a lot easier to understand!

  6. cbracken commented on Feb 17, 2022

    @cbracken
    Member
  7. added
    P2Important issues not at the top of the work list
    on Feb 17, 2022
  8. added
    frameworkflutter/packages/flutter repository. See also f: labels.
    on Feb 22, 2022
  9. gspencergoog commented on Jan 19, 2023

    @gspencergoog
    Contributor

    Could #118403 be a new incident of this?

  10. tgucio commented on Jan 19, 2023

    @tgucio
    ContributorAuthor

    @gspencergoog I think they could be separate issues - here it's simple (albeit abused a bit) combining characters, #118403 is when text shaping (glyph substitution + positioning) kicks in.

  11. justinmc commented on Jan 21, 2023

    @justinmc
    Contributor

    Just as some quick analysis, the "Zalgo" string in the description is of length 50 but contains 5 characters. The arrow keys correctly traverse the string in 5 key presses, but the cursor never appears visually between the first and second characters as noted above.

    Screencast.from.2023-01-20.16-38-08.webm

    Here's the code that decides where to put the selection when the left arrow key is pressed (and trailing just below for the right arrow):

    int? getLeadingTextBoundaryAt(int position) {

    That appears to be working correctly at first glance. I wonder if the problem is drawing the cursor in the incorrect visual place given a correct TextSelection?

  12. added a commit that references this issue on Mar 12, 2023
    5af3fde
  13. gnprice commented on Mar 12, 2023

    @gnprice
    Member

    This turned out to have the same cause as #118403 after all, as well as #50563; I've just sent a fix as #122480. It also turns out to be purely within the framework.

  14. removed
    engineflutter/engine related. See also e: labels.
    on Mar 12, 2023
  15. added
    r: fixedIssue is closed as already fixed in a newer version
    on Mar 28, 2023
  16. github-actions commented on Apr 11, 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.

  17. locked as resolved and limited conversation to collaborators on Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work lista: desktopRunning on desktopa: text inputEntering text in a text field or keyboard related problemsc: regressionIt was better in the past than it is nowfound in release: 2.10Found to occur in 2.10found in release: 2.11Found to occur in 2.11frameworkflutter/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/packagesr: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions