MohamedRejeb / compose-rich-editor

A Rich text editor library for both Jetpack Compose and Compose Multiplatform, fully customizable, supports HTML and Markdown.
https://mohamedrejeb.github.io/compose-rich-editor/
Apache License 2.0
1.15k stars 71 forks source link

Allow implementing editor actions differently #67

Open wakaztahir opened 1 year ago

wakaztahir commented 1 year ago

Currently the editor options support addCode, addBold, This is like a toggle which turns on and user keeps going with the styles

However some people prefer editing differently , like myself , for example when I click bold , I want editor to grab the current word and just make it bold , unless I have a selection, This also allows editor to have no state other than selection, Not that previous API shouldn't be the way, but there's no way currently to do the above.

So Editor State of isBold on currently , isItalic on should be separated from the editor and allowed to have a different state

I implemented this initially in my editor which doesn't retain styles

https://github.com/Qawaz/markdown-compose/blob/5293904088ab9ace4d4b1e7e7788437cadd513d6/md-compose-core/src/commonMain/kotlin/com/wakaztahir/markdowncompose/editor/utils/TextFormatter.kt#L121

MohamedRejeb commented 1 year ago

Do you mean like when I type some text, ex "Hello world|", and the cursor is directly after "world" and when I click bold "world" became bold ?

wakaztahir commented 1 year ago

yes , this way when my cursor is in range of that word , if its already bold , pressing bold unbolds it and button reflects that the current word under cursor is bold

MohamedRejeb commented 1 year ago

Well I still not understand your point exactly xD can you attach a short recording.

wakaztahir commented 1 year ago

https://github.com/MohamedRejeb/Compose-Rich-Editor/assets/42442700/c0322926-32af-4052-8bba-b175b9f15703

In the end when I move the cursor the styles are lost , this is because the editor doesn't retail styles

When I move the cursor to another word , the button indicates that the current word is not bold and when you press it bolds it and when go back to word you bolded previously , you can unbold it

MohamedRejeb commented 1 year ago

This looks good UX for mobile users, did you make this using this library ? Because I think that it's not possible to do it with the available public Api's.

MohamedRejeb commented 1 year ago

I was trying to mimic the UX of the most common rich text editors. I'll think of adding some option to make this possible.

wakaztahir commented 1 year ago

The code is available , I've made a link to it , It works with Annotated String and text field value that the outlined text field holds , only problem was retaining styles due to an unavailable saver implementation