Skip to content

Flutter's text input plugin should report deltas instead of full text blocks #87972

@matthew-carroll

Description

@matthew-carroll

When a user makes changes to text content, Flutter doesn't report the change in content. Instead, Flutter reports the entire text block with various changes already applied to the text block.

Without the knowledge of text change deltas, it's impossible implement attributed text editing, e.g., styled text, text with links, text separated across document nodes. A delta would inform the text editor how to expand, contract, add, or remove attributions. Without delta information, it's impossible to be sure that attribution changes are appropriate/correct.

How to implement on Android
Currently, Flutter uses SpannableStringBuilder to implement Editable. Instead, Flutter should directly implement Editable and forward the deltas to the framework. Let the framework apply the deltas for the simple use-cases.

How to implement on iOS
I'm not familiar with the iOS side, but a quick search through the docs shows UITextInput and UIKeyInput.

With regard to mobile, I'm sure there is a solution here. It could be taken in two different directions:

  1. Replicate the platform-specific APIs so that Android and iOS developers have the exact same control as their underlying platform.
  2. Create a robust, but common interface that represents deltas on Android and iOS in the same way.

I would recommend doing both 1 and 2, but due to the time pressure that some users have, I would start with 2, which is faster, and then backport to 1.

What about other platforms?
I don't know if web and desktop offer delta information for text changes. I bet they do, because otherwise it's unclear how any rich text editors would be implemented. However, if no similar delta API is available, Flutter still needs to pipe through the mobile deltas. Web and desktop can utilize keyboard listeners, if needed, but mobile only offers a single text editing interface and it's the IME interface that goes through Flutter's text input plugin.

Metadata

Metadata

Assignees

Labels

P0Critical issues such as a build break or regressiona: text inputEntering text in a text field or keyboard related problemscustomer: todoframeworkflutter/packages/flutter repository. See also f: labels.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions