Repository: flutter
Issue: [macOS] Japanese-kana input with live conversion disabled produces weird characters
Labels: a: text input,engine,platform-mac,a: internationalization,has reproducible steps,P2,found in release: 3.16,found in release: 3.19,fyi-text-input,team-macos,triaged-macos

### Steps to reproduce

1. Change keyboard to "Japanese - Kana" and disable "Live conversion":
 ![Screenshot 2024-01-16 at 10 12 27](https://github.com/superlistapp/super_editor/assets/31278849/8fb8d5cb-ed17-49a8-bad4-a360aac13048)
2. Run the sample code on macOS
3. Type querty
4. Pick the suggestion from the popover list 

### Expected results

Conversion takes place and the content is replaced.

### Actual results

An invalid character is reported when pressing the down arrow to select the suggestion and its maintained after picking the selection.

### Code sample

<details><summary>Code sample</summary>

```dart
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

void main() {
  runApp(
    const MaterialApp(
      home: Scaffold(
        body: TextInputExample(),
      ),
    ),
  );
}

class TextInputExample extends StatefulWidget {
  const TextInputExample({super.key});

  @override
  State<TextInputExample> createState() => _TextInputExampleState();
}

class _TextInputExampleState extends State<TextInputExample> implements DeltaTextInputClient {
  final FocusNode _focusNode = FocusNode();
  final GlobalKey _textKey = GlobalKey();

  TextInputConnection? _inputConnection;
  TextEditingValue _currentEditingValue = const TextEditingValue(
    text: 'Type "querty" and pick the option on the popover: ',
    selection: TextSelection.collapsed(offset: 49),
  );

  @override
  void initState() {
    super.initState();
    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
      _attach();
      _reportVisualInformationToIme();
    });
  }

  @override
  void dispose() {
    _focusNode.dispose();
    super.dispose();
  }

  @override
  void updateEditingValueWithDeltas(List<TextEditingDelta> textEditingDeltas) {
    print('Received ${textEditingDeltas.length} deltas');
    TextEditingValue newEditingValue = _currentEditingValue;

    for (final delta in textEditingDeltas) {
      print(delta);
      newEditingValue = delta.apply(newEditingValue);
    }

    setState(() {
      _currentEditingValue = newEditingValue;
    });
  }

  void _attach() {
    if (_inputConnection != null) {
      return;
    }
    _inputConnection = TextInput.attach(
      this,
      const TextInputConfiguration(
        enableDeltaModel: true,
        inputType: TextInputType.multiline,
        textCapitalization: TextCapitalization.sentences,
        inputAction: TextInputAction.newline,
        keyboardAppearance: Brightness.light,
      ),
    );
    _inputConnection!.show();
    _inputConnection!.setEditingState(_currentEditingValue);
  }

  KeyEventResult _onKeyEvent(FocusNode node, KeyEvent event) {
    // Let the OS handle the keys.
    return KeyEventResult.skipRemainingHandlers;
  }

  void _reportVisualInformationToIme() {
    final myRenderBox = context.findRenderObject() as RenderBox?;
    if (myRenderBox != null && myRenderBox.hasSize) {
      _reportSizeAndTransformToIme();
      _reportCaretRectToIme();
    }
  }

  void _reportSizeAndTransformToIme() {
    final renderBox = _textKey.currentContext!.findRenderObject() as RenderBox;

    final size = renderBox.size;
    final transform = renderBox.getTransformTo(null);

    _inputConnection!.setEditableSizeAndTransform(size, transform);
  }

  void _reportCaretRectToIme() {
    _inputConnection!.setCaretRect(Rect.zero);
  }

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Focus(
        focusNode: _focusNode,
        autofocus: true,
        onKeyEvent: _onKeyEvent,
        child: DecoratedBox(
          decoration: BoxDecoration(border: Border.all()),
          child: Text(
            key: _textKey,
            _currentEditingValue.text,
            textAlign: TextAlign.center,
          ),
        ),
      ),
    );
  }

  @override
  void connectionClosed() {}

  @override
  AutofillScope? get currentAutofillScope => null;

  @override
  TextEditingValue? get currentTextEditingValue => null;

  @override
  void insertTextPlaceholder(Size size) {}

  @override
  void performAction(TextInputAction action) {}

  @override
  void performPrivateCommand(String action, Map<String, dynamic> data) {}

  @override
  void removeTextPlaceholder() {}

  @override
  void showAutocorrectionPromptRect(int start, int end) {}

  @override
  void showToolbar() {}

  @override
  void updateEditingValue(TextEditingValue value) {}

  @override
  void updateFloatingCursor(RawFloatingCursorPoint point) {}

  @override
  void didChangeInputControl(TextInputControl? oldControl, TextInputControl? newControl) {}

  @override
  void insertContent(KeyboardInsertedContent content) {}

  @override
  void performSelector(String selectorName) {}
}

```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

https://github.com/flutter/flutter/assets/7597082/b1974df2-cc34-4147-b860-d440bd303632

Same input on Safari:

https://github.com/flutter/flutter/assets/7597082/599a6e70-e561-45ff-b4e3-54d913865793
</details>


### Logs

<details open><summary>Logs</summary>

```console
Restarted application in 351ms.
flutter: Received 1 deltas
flutter: TextEditingDeltaInsertion#457a9(oldText: Type "querty" and pick the option on the popover:, textInserted: た, insertionOffset: 49, selection: TextSelection.collapsed(offset: 50, affinity: TextAffinity.downstream, isDirectional: false), composing: TextRange(start: 49, end: 50))
flutter: Received 1 deltas
flutter: TextEditingDeltaInsertion#0b786(oldText: Type "querty" and pick the option on the popover:た, textInserted: な, insertionOffset: 50, selection: TextSelection.collapsed(offset: 51, affinity: TextAffinity.downstream, isDirectional: false), composing: TextRange(start: 49, end: 51))
flutter: Received 1 deltas
flutter: TextEditingDeltaInsertion#64275(oldText: Type "querty" and pick the option on the popover:たな, textInserted: い, insertionOffset: 51, selection: TextSelection.collapsed(offset: 52, affinity: TextAffinity.downstream, isDirectional: false), composing: TextRange(start: 49, end: 52))
flutter: Received 1 deltas
flutter: TextEditingDeltaInsertion#ad543(oldText: Type "querty" and pick the option on the popover:たない, textInserted: す, insertionOffset: 52, selection: TextSelection.collapsed(offset: 53, affinity: TextAffinity.downstream, isDirectional: false), composing: TextRange(start: 49, end: 53))
flutter: Received 1 deltas
flutter: TextEditingDeltaInsertion#6473f(oldText: Type "querty" and pick the option on the popover:たないす, textInserted: か, insertionOffset: 53, selection: TextSelection.collapsed(offset: 54, affinity: TextAffinity.downstream, isDirectional: false), composing: TextRange(start: 49, end: 54))
flutter: Received 1 deltas
flutter: TextEditingDeltaInsertion#89424(oldText: Type "querty" and pick the option on the popover:たないすか, textInserted: ん, insertionOffset: 54, selection: TextSelection.collapsed(offset: 55, affinity: TextAffinity.downstream, isDirectional: false), composing: TextRange(start: 49, end: 55))
flutter: Received 1 deltas
flutter: TextEditingDeltaReplacement#aeb0c(oldText: Type "querty" and pick the option on the popover:たないすかん, textReplaced: たないすかん, replacementText: , replacedRange: TextRange(start: 49, end: 55), selection: TextSelection.collapsed(offset: 50, affinity: TextAffinity.downstream, isDirectional: false), composing: TextRange(start: -1, end: -1))
flutter: Received 1 deltas
flutter: TextEditingDeltaInsertion#5ca18(oldText: Type "querty" and pick the option on the popover:, textInserted: たないすかん, insertionOffset: 50, selection: TextSelection.collapsed(offset: 56, affinity: TextAffinity.downstream, isDirectional: false), composing: TextRange(start: -1, end: -1))
Application finished.

Exited.

```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[✓] Flutter (Channel master, 3.19.0-9.0.pre.202, on macOS 14.2.1 23C71
    darwin-arm64, locale pt-BR)
    • Flutter version 3.19.0-9.0.pre.202 on channel master at
      /Users/angelosilvestre/dev/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision db828a8351 (3 days ago), 2024-01-27 01:33:10 -0500
    • Engine revision 95e9a15fd9
    • Dart version 3.4.0 (build 3.4.0-80.0.dev)
    • DevTools version 2.31.0

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/angelosilvestre/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android
      Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[!] Xcode - develop for iOS and macOS (Xcode 15.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15C500b
    ! CocoaPods 1.12.1 out of date (1.13.0 is recommended).
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin
        code that responds to your plugin usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To upgrade see
      https://guides.cocoapods.org/using/getting-started.html#updating-cocoapods
      for instructions.

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.3)
    • 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
      17.0.6+0-17.0.6b829.9-10027231)

[✓] VS Code (version 1.85.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.80.0

[✓] Connected device (3 available)
    • sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64  • Android 14
      (API 34) (emulator)
    • macOS (desktop)             • macos         • darwin-arm64   • macOS
      14.2.1 23C71 darwin-arm64
    • Chrome (web)                • chrome        • web-javascript • Google
      Chrome 121.0.6167.85

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.
```

</details>