Hi all, I’ve been using the `BasicTextField` with ...
# compose
j
Hi all, I’ve been using the
BasicTextField
with
AnnotatedString
but when I place the cursor in the component the
styles
are empty and I just get a plain text. Is there any way to get the
AnnotatedString
with the
styles
when a change is made?
h
Unfortunately, no. BasicTextField's buffer removes all styling from AnnotatedString before
onValueChange
triggers for the first time.
j
@Halil Ozercan why the component has that behavior?
I think if the component is able to accept
AnnotatedString
the normal behavior is to get all the styles with the text when value changes. I don’t found the reason why the styles are removed.
h
This is a limitation of internal buffer used by BasicTextField. We are aware of the problem and planning to address it.
a
thats great to hear!
@Jorge Rodríguez there is this library (and my Multiplatform version of it) that attempts to implement rich text editing on top of
BasicTextField
however it is definitely a hack. We store an external copy of all of the styling, and then re-apply the styling after setting the value.
@Halil Ozercan in working on that rich text editor library, it occurs to me that we're missing some more fine-grained call backs in order to be able to have a more advanced text editor. I'd love to be able to know WHAT text changed when I get a
onTextChanged
type of callback. Currently we just get the whole value again
j
@Adam Brown I'm working also in a Rich Text Editor. I will take a look your library and also @Halil Ozercan nice to hear about that and also could be great to have more granularity in the textfield changes in case of rich text editors
h
We will hopefully have more to share in near future. There is definitely a need for more granular information on text changes. All I can say is stay tuned 🙂 Also, thanks all for your hard work to contribute to the community. We believe it's gonna get much easier to build awesome text editors in Compose 🤞
j
@Halil Ozercan thanks for the information.
@Adam Brown there is an issue with the library when you type characters fast or when applying styles and the adding a space to the text, I was fixing on my local project also integrating with some extra code that we have in KMM. I’m still understanding the code but seems to have some bugs related to TextRange as mentioned.
a
ya, I'm not sure they are totally fixable without some new APIs on
BasicTextField
j
I have fixed the issue. On the other hand I’m not sure if there is an alpha version or where can I see the progress of
BasicTextField2
@Halil Ozercan?
h
The latest alpha of foundation includes
BasicTextField2
but it's in a very rough state for now. You can give it a try to check the new API and get an idea about where it's evolving towards.
j
Thanks @Halil Ozercan, it would be great to have some extension to handle list formats or to put other composables inside the
BasicTextField2
the same way the
BasicText
do with placeholders.
a
@Halil Ozercan oh very cool, I'll check it out!
@Halil Ozercan I've been playing with
BasicTextField2
and its looking really good so far! One thing I think would be hard at the moment I think is undo/redo. I think the guts are there maybe with the internal
ChangeTracker
? If that is exposed it should be possible I think.
h
@Adam Brown I'm glad to hear that you are enjoying the new API. We are of course planning to support undo/redo at least internally just like in the current BasicTextField. It's also in consideration to expose an API to control it from outside. Also, why do you think it's hard to add undo/redo right now? Wouldn't
forEachTextValue
or
textAsFlow
help you keep track of observed values to reset back to? You can even add some kind of debounce to skip intermediate steps during fast typing. Use
edit
to reset TextFieldState to any value you want.
cc: @Zach Klippenstein (he/him) [MOD]
z
I wouldn’t bother implementing undo/redo on top of BTF2 at this point - it’s not usable for a thousand other reasons at this time, so it would be wasted work
a
@Halil Ozercan My thinking was that I would want to debounce based on certain events. So I might keep just taking typing events, but the moment you change the selection or add a selection or whatever, demarcate right there and create a new undo point
and also probably skip selection events entirely from the undo redo history
j
During this week I will be playing with the new BTF2 and share my findings
a
I know this is super early in development, but do you have any very rough timeline of when BTF2 is planned to be released? it's it in 1.5.0?
z
I can’t say for sure, it’s a large project and any number of things could delay it. But we are hoping to target roughly the end of the year.
a
@Halil Ozercan you asked why I would want external access to the undo/redo history, it's because I would want to be persisting it past the life time of the composable.