-
-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[Apply ordered and unordered list to all selection, event if selected multiple paragraphos] (Update RichTextState.kt) #257
Conversation
MedvedevaElena
commented
Apr 18, 2024
- made functions toggleUnorderedList and toggleUnorderedList work with multiple paragraphs
- added deprecared annotation to fuctions, that became private, if someone used it (I don't know, if it important)
[Apply ordered and unordered list to all selection, event if selected multiple paragraphos] - made functions toggleUnorderedList and toggleUnorderedList work with multiple paragraphs - added deprecared annotation to fuctions, that became private, if someone used it (I don't know, if it important)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi,
Thanks for your contribution. I think that add and remove lists functions can be implemented the same way as the toggle function.
val paragraph = getRichParagraphByTextIndex(selection.min - 1) ?: return | ||
if (paragraph.type is OrderedList) removeOrderedList() | ||
else addOrderedList() | ||
val firstParagraph = getRichParagraphByTextIndex(selection.min - 1) ?: return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why you are getting the first paragraph here, the paragraph list should be enough.
And if the list if empty, you can return
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the tip!
When I tested the new version, I've found out, that when I tap on text only, without any selection, list styles doesn't applied to current paragraph. It occures because getRichParagraphListByTextRange() returns empty list. So, I've edited getRichParagraphListByTextRange() for this case.
If it's not good for the main concept, I can create separate function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's fine now. The getRichParagraphListByTextRange
method should return data even if the selection is collapsed.
val firstParagraph = getRichParagraphByTextIndex(selection.min - 1) ?: return | ||
val paragraphs = getRichParagraphListByTextRange(selection).toMutableList() | ||
if (paragraphs.isEmpty()) { | ||
paragraphs.add(firstParagraph) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should return here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ready
fun addOrderedList() { | ||
val paragraph = getRichParagraphByTextIndex(selection.min - 1) ?: return | ||
addOrderedList(paragraph) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, this shouldn't be deprecated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ready
fun removeOrderedList() { | ||
val paragraph = getRichParagraphByTextIndex(selection.min - 1) ?: return | ||
removeOrderedList(paragraph) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, this shouldn't be deprecated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ready
val paragraph = getRichParagraphByTextIndex(selection.min - 1) ?: return | ||
if (paragraph.type is UnorderedList) removeUnorderedList() | ||
else addUnorderedList() | ||
val firstParagraph = getRichParagraphByTextIndex(selection.min - 1) ?: return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why you are getting the first paragraph here, the paragraph list should be enough.
And if the list if empty, you can return
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As with Ordered List, changed
val firstParagraph = getRichParagraphByTextIndex(selection.min - 1) ?: return | ||
val paragraphs = getRichParagraphListByTextRange(selection).toMutableList() | ||
if (paragraphs.isEmpty()) { | ||
paragraphs.add(firstParagraph) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should return here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ready
fun addUnorderedList() { | ||
val paragraph = getRichParagraphByTextIndex(selection.min - 1) ?: return | ||
addUnorderedList(paragraph) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this shouldn't be deprecated, but it can work the same as toggle.
- Get the list of the selected paragraphs.
- call addUnorderedList on each paragraph.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ready
fun removeUnorderedList() { | ||
val paragraph = getRichParagraphByTextIndex(selection.min - 1) ?: return | ||
removeUnorderedList(paragraph) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, this shouldn't be deprecated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ready
[Apply ordered and unordered list to all selection, event if selected multiple paragraphos] - removed @deprecated attributes - made simplier toggleOrderedList & toggleUnorderedList - made getRichParagraphListByTextRange to return not empty list even when selection collapsed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I will check it on my side before merging to main.
Thanks for your contribution.