superlistapp / super_editor

A Flutter toolkit for building document editors and readers
https://superlist.com/SuperEditor/
MIT License
1.68k stars 245 forks source link

Text replacement does not work #1890

Open miguelcmedeiros opened 8 months ago

miguelcmedeiros commented 8 months ago

Package Version main branch with commit hash https://github.com/superlistapp/super_editor/commit/8a2a32fc2611f91de8834101f00d571845554b9b

To Reproduce

  1. Go to SuperEditor or SuperTextField demo
  2. On a new line type "omw"

Actual behavior Nothing happens.

Expected behavior Assuming that "omw" is configured to be replaced as "On my way!", then the following should be shown: Screenshot 2024-03-11 at 13 08 44

Platform All platforms.

Flutter version Flutter master commit e278279a48f0479386c249cf18f26b29c6f9018f.

Additional context It's possible to check which text replacements are configured on macOS here: CleanShot 2023-08-17 at 13 02 51@2x

miguelcmedeiros commented 8 months ago

Cc @matthew-carroll

angelosilvestre commented 8 months ago

@miguelcmedeiros I looked into this and it seems that the text input client doesn't call any callbacks when the user types a text that matches a configured replacement.

Even Flutter's TextField doesn't seem to support that. I filed https://github.com/flutter/flutter/issues/145122

I'm not sure if there is some native API call for that, or if we need to query the configured replacements and implement the behavior ourselves.

miguelcmedeiros commented 7 months ago

@angelosilvestre I tried the sample app in DartPad: https://dartpad.dev/?sample=google-ai-sdk It has a text field the text replacement worked fine there:

https://github.com/superlistapp/super_editor/assets/31278849/e43e43f6-a246-4de7-bf19-840f5c3d17f7

angelosilvestre commented 7 months ago

@miguelcmedeiros This seems to work on web only, it's the browser's hidden html input that makes it work.

If we run the example app on web it does show the popover, but selecting the value causes a crash and the text isn't replaced:

https://github.com/superlistapp/super_editor/assets/7597082/40f7c7f5-6a0a-4516-b390-4dfd3a8c035a

We can fix that, but it will still be an incomplete solution, because it will only work on web.

cammcnab commented 7 months ago

One minor detail is the same text replacements do work on iOS currently (in the Superlist app), likely because of the way the text suggestion bar above the keyboard handles replacements? 🤷‍♂️

angelosilvestre commented 7 months ago

@cammcnab Text replacement seems to work differently on iOS. On iOS, the IME generates the suggestions on the keyboard panel. On macOS, it seems the IME doesn't show automatically show the suggestion popover nor generate any signals for us to show a popover.