Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the concept of '_ controller. onDelete' to set the value of '_ handleDelete'; Deleting UTF-16 emoticons doesn't work properly, what should I do #2331

Open
1 task done
zhaofeixaing opened this issue Oct 22, 2024 · 0 comments
Labels
question Further information is requested

Comments

@zhaofeixaing
Copy link

zhaofeixaing commented Oct 22, 2024

Is there an existing issue for this?

The question

Use the concept of '_ controller. onDelete' to set the value of '_ handleDelete'; Deleting UTF-16 emoticons doesn't work properly, what should I do
新标签页 - Awesome Screenshot - Awesome Screenshot.webm
这个是我的代码

 @override
  void initState() {
    super.initState();
    _controller.document = widget.args.document;

    _controller.onDelete = _handleDelete;
    // textEditingValue
  }

  void _handleDelete(int cursorPosition, bool forward) {
    print('Delete at position: $cursorPosition, forward: $forward');
    final doc = _controller.document.toPlainText();
    final characters = doc.characters;

    if (forward) {
      if (cursorPosition < characters.length) {
        final newText = characters.take(cursorPosition).toString() + characters.skip(cursorPosition + 1).toString();
        _controller.replaceText(
          cursorPosition,
          1,
          '',
          TextSelection.collapsed(offset: cursorPosition),
        );
      }
    } else {
      if (cursorPosition > 0) {
        final newText = characters.take(cursorPosition - 1).toString() + characters.skip(cursorPosition).toString();
        _controller.replaceText(
          cursorPosition - 1,
          1,
          '',
          TextSelection.collapsed(offset: cursorPosition - 1),
        );
      }
    }
  }

Running error

════════ Exception caught by painting library ══════════════════════════════════
The following ArgumentError was thrown while building a TextSpan:
Invalid argument(s): string is not well-formed UTF-16

@zhaofeixaing zhaofeixaing added the question Further information is requested label Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant