Repository: flutter
Issue: RTL textField Cursor movement has a problem with the last position and Emojies and text selection
Labels: a: text input,framework,has reproducible steps,P2,f: selection,found in release: 3.7,found in release: 3.8,team-framework,triaged-framework

## Steps to Reproduce

1. Execute `flutter run` on the code sample
2. type some things in text field like Screenshots that are attached 
3. try to move the cursor on different words and goes to the last words and move the cursor to the last position

**Expected results:** we want the cursor to move to the last position without any problems 

**Actual results:** As indicated in the screenshots the cursor stuck before the last position and can't move it to last position of words

for an additional report, this problem occurs when using a Persian or Arabic keyboard for typing and we use a special font for our text this makes other bugs that this issue repeats for each line of text for the normal situation this just occurs on the last line of the paragraph. also if using Emojies this problem repeats again or for text selection, we can select the last character of words.

another issue that should be mentioned here is the cursor movement problem for Persian keyboards when characters stick together this makes a bug that the issue stuck in the wrong position and when u typing something these words display in another position that does not match with your selected position


<details>
<summary>
Sample Code put on main.dart
</summary>

<!--
      Please create a minimal reproducible sample that shows the problem
      and attach it below between the lines with the backticks.

      To create it you can use `flutter create bug` command and update the `main.dart` file.

      Alternatively, you can use https://dartpad.dev/
      which is capable of creating and running small Flutter apps.

      Without this we will unlikely be able to progress on the issue, and because of that
      we regretfully will have to close it.
-->

```import 'package:flutter/cupertino.dart';
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> {
  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.headlineMedium,
            ),
            Padding(
              padding: const EdgeInsets.all(28.0),
              child: TextField(textDirection: TextDirection.rtl,maxLines: null,),
            )
          ],
        ),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: _incrementCounter,
        tooltip: 'Increment',
        child: const Icon(Icons.add),
      ),
    );
  }
}
```

</details>

<details>
  <summary>Logs</summary>


```

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.7.1, on Microsoft Windows [Version 10.0.19044.2486], locale en-US)
[√] Windows Version (Installed version of Windows is version 10 or higher)
[√] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Professional 2019 16.11.22)  
[√] Android Studio (version 2021.1)
[√] IntelliJ IDEA Community Edition (version 2021.3)
[√] VS Code (version 1.73.1)
[√] Connected device (4 available)
[!] HTTP Host Availability
    X HTTP host "https://cocoapods.org/" is not reachable. Reason: An error occurred while checking the HTTP host: The connection terminated during
      handshake

! Doctor found issues in 1 category.

```


```
```

</details>

![image](https://user-images.githubusercontent.com/28021064/216844904-4bdf93c7-468d-4e8c-af7d-cb7dcc533326.png)
The image about the cursor stuck behind the last Emojies

![image](https://user-images.githubusercontent.com/28021064/216844934-882be4c4-5efb-4f2a-a860-51615216c36f.png)
this image is about moving the cursor to the middle of the words and the cursor stuck in this position but if u typing, type in another position

![image](https://user-images.githubusercontent.com/28021064/216845003-deeea823-9d3a-4223-b531-1a166d9933b3.png)
this image is about the problem with the last char of a word that doesn't let you move the cursor behind it or select it


https://user-images.githubusercontent.com/28021064/216845203-1eccc103-6252-4e1c-9434-885992e0ccbc.mp4
the video that shows the problem with the cursor on Persian words