Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Apply ordered and unordered list to all selection, event if selected multiple paragraphos] (Update RichTextState.kt) #257

Conversation

MedvedevaElena
Copy link
Contributor

  • 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)
Copy link
Owner

@MohamedRejeb MohamedRejeb left a 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
Copy link
Owner

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

Copy link
Contributor Author

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

Copy link
Owner

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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should return here

Copy link
Contributor Author

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)
Copy link
Owner

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.

Copy link
Contributor Author

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)
Copy link
Owner

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.

Copy link
Contributor Author

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
Copy link
Owner

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

Copy link
Contributor Author

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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should return here

Copy link
Contributor Author

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)
Copy link
Owner

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.

Copy link
Contributor Author

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)
Copy link
Owner

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.

Copy link
Contributor Author

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
Copy link
Owner

@MohamedRejeb MohamedRejeb left a 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.

@MohamedRejeb MohamedRejeb changed the base branch from main to 1.x April 19, 2024 07:08
@MohamedRejeb MohamedRejeb merged commit 6d6b418 into MohamedRejeb:1.x Apr 19, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants