Repository: flutter
Issue: [Desktop] TextField with pasted CRLF endings has invisible CR char
Labels: a: text input,framework,platform-windows,a: desktop,has reproducible steps,P2,found in release: 2.5,found in release: 2.6,found in release: 2.8,team-windows,triaged-windows

When I paste some text with CRLF endings into a TextField and click on the end of the line, cursor is placed after invisible `\r` char. When I press left arrow, it goes over that char to the actual text end. Now when I press right arrow, it skips to the next line like there wasn't any additional char. But that `\r` is still there after I click there with mouse again.

I found that it is `\r` by selecting it and pasting it into hex editor.

This only happens in Windows build, tried on web and it doesn't happen there. Don't know about the other platforms.

<details>
<summary>Code sample</summary>

```dart
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(
      home: Scaffold(
        body: Container(
          padding: const EdgeInsets.all(8),
          child: const TextField(
            style: TextStyle(fontSize: 50),
            expands: true,
            minLines: null,
            maxLines: null,
          ),
        ),
      ),
    );
  }
}
```

</details>

<details>
  <summary>Logs</summary>

```
[√] Flutter (Channel beta, 2.8.0-3.1.pre, on Microsoft Windows [Version 10.0.22000.318], locale en-GB)
    • Flutter version 2.8.0-3.1.pre at C:\Users\husar\AppData\Local\Flutter\SDK\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 3dab555040 (7 days ago), 2021-11-12 11:50:00 -0800
    • Engine revision 09f1520e8b
    • Dart version 2.15.0 (build 2.15.0-268.8.beta)

[!] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
    • Android SDK at C:\Users\husar\AppData\Local\Android\sdk
    X cmdline-tools component is missing
      Run `path/to/sdkmanager --install "cmdline-tools;latest"`
      See https://developer.android.com/studio/command-line for more details.
    X Android license status unknown.
      Run `flutter doctor --android-licenses` to accept the SDK licenses.
      See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.

[√] 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.0)
    • Visual Studio at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
    • Visual Studio Community 2019 version 16.11.31605.320
    • Windows 10 SDK version 10.0.19041.0

[√] Android Studio (version 4.0)
    • Android Studio at C:\Program Files\Android\Android Studio
    • Flutter plugin version 47.1.2
    • Dart plugin version 193.7361
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

[√] IntelliJ IDEA Community Edition (version 2021.2)
    • IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2021.2
    • 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

[√] VS Code, 64-bit edition (version 1.62.2)
    • VS Code at C:\Program Files\Microsoft VS Code
    • Flutter extension version 3.28.0

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.22000.318]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 95.0.4638.69
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 93.0.961.52

! Doctor found issues in 1 category.
```

</details>

Video:



https://user-images.githubusercontent.com/13891066/142689108-0109464f-b223-41cf-bc75-83b9f90373f0.mp4



EDIT:
By pasting text with CRLF line endings I meant like when you open some file with text and that text has `\r\n` as line endings. You select that text and paste it into TextField.

I have created another repro with comparison of LF / CRLF.

<details>
<summary>Code sample</summary>

```dart
import 'dart:io';

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 const MaterialApp(
      home: Main(),
    );
  }
}

class Main extends StatefulWidget {
  const Main({Key? key}) : super(key: key);

  @override
  _MainState createState() => _MainState();
}

class _MainState extends State<Main> {
  final _lfFilePath = 'C:/Projects/Flutter/bug_repro/lf.txt';
  final _crlfFilePath = 'C:/Projects/Flutter/bug_repro/crlf.txt';

  final _lfController = TextEditingController();
  final _crlfController = TextEditingController();

  @override
  void initState() {
    super.initState();
    _lfController.text = File(_lfFilePath).readAsStringSync();
    _crlfController.text = File(_crlfFilePath).readAsStringSync();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        padding: const EdgeInsets.all(8),
        child: Column(
          mainAxisSize: MainAxisSize.max,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            const Text('LF'),
            Expanded(
              child: TextField(
                controller: _lfController,
                style: const TextStyle(fontSize: 50),
                expands: true,
                minLines: null,
                maxLines: null,
              ),
            ),
            const Text('CRLF'),
            Expanded(
              child: TextField(
                controller: _crlfController,
                style: const TextStyle(fontSize: 50),
                expands: true,
                minLines: null,
                maxLines: null,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
```

</details>

Download these two files:
[crlf.txt](https://github.com/flutter/flutter/files/7588894/crlf.txt)
[lf.txt](https://github.com/flutter/flutter/files/7588895/lf.txt)

Both are created in VS Code and one is just saved with CRLF endings and the other one with LF endings:
![image](https://user-images.githubusercontent.com/13891066/143046452-90bbbe67-0b06-4dd7-89ce-c3f3f792f8ad.png)

Change paths to yours in `_lfFilePath` and `_crlfFilePath` variables, run it.

If you place cursor at the end of the line, in the LF part is everything ok
![image](https://user-images.githubusercontent.com/13891066/143046717-ecd74467-d90f-4f50-a3f3-19137fb1f173.png)

But in the CRLF part is this invisible `\r` char:
![image](https://user-images.githubusercontent.com/13891066/143046954-93929c1f-c9cd-419e-b95c-260ff7067e22.png)

I have also noticed that when you copy / paste it, Windows (presumably?) automatically converts LF to CRLF, so this actually happens even if you try to copy / paste LF text. But by directly comparing those two files it's clearer.