Adam Brown
02/27/2025, 6:15 AMTextField
for a long time now, but the limitations of BasicTextField
have ultimately made that impossible.
So a few months ago I thought I'd just explore how hard it would be to re-implement a Text Editor from scratch in Compose. Turns out, ya, it's pretty hard 😂 But I have a working version now that might be useful to some!
You can try a wasmJS demo of it here.
Features:
• Semi-efficient text handling for long form text
• Arbitrary text styling
• Extended styling system: RichSpanStyle allows for fully custom drawing
• Markdown support
• Spell Checking!!! 🥳
• Desktop/JVM, Android, wasmJs support (other targets should be possible too)
Now hopefully Compose proper will get a rich text capable component, that is also suitable for long-form text, and I can just deprecate this project. But until then, there's ComposeTextEditorLibrary.
https://github.com/Wavesonics/ComposeTextEditorLibraryDave Leeds
02/27/2025, 3:25 PMAdam Brown
02/27/2025, 8:15 PMAnnotatedString
under the hood, but can parse to and from markdownAdam Brown
02/28/2025, 4:23 AMDave Leeds
02/28/2025, 3:46 PMJorge Martín
03/03/2025, 11:47 AMEditText
with a custom InputConnection
for this).
However, there are a couple of issues I found and I think they're all related to not using the TextInputService / PlatformTextInputModifierNode:
• Since no text input session is started on focus, at least on my test in the emulator, the IME keyboard won't be displayed so I can only type using the HW keyboard.
• Although it's mentioned in the README, RTL languages won't work, and I think it's again because text input is done through the onKeyPreview
modifier instead of using the text input service or the text input modifier and intercepting the EditCommand
s received from the IME. Alternatively, I tried using a special case for the case when the KeyEvent
action is MULTIPLE and keycode is UNKNOWN in Android code to be able to get the characters
contents of the KeyEvent
and it worked, kind of, although it's not the right solution.
• The best way to solve this would be implementing 'composition' so Chinese/Japanese/Korean languages where merging characters is important would work, and it would also allow suggestions other languages to work, so the text field would work way closer to any other in the system.
• As mentioned in the previous point, no IME integration means no suggestions, so no way to quickly fix typos in mobile.
So IMO if you want to continue this experiment you should probably try to make it work through the mentioned input service / modifier node since otherwise, at least in platforms where the IME is important, you're fighting the platform (been there, done that, I wouldn't recommend it to anyone 😅).
This is not a complaint about the library, the work done trying to make each part of the text editor customisable is amazing, but since I had previous experience working on something related I thought I could try to give you some suggestions about which path is more likely to succeed in the long term.Adam Brown
03/03/2025, 7:16 PMTextInputService
My primary target was Desktop, so I didn't notice the problems with not using it until late in testing.