Skip to content
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

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -551,14 +551,24 @@ class RichTextState internal constructor(
}

fun toggleUnorderedList() {
val paragraph = getRichParagraphByTextIndex(selection.min - 1) ?: return
if (paragraph.type is UnorderedList) removeUnorderedList()
else addUnorderedList()
val paragraphs = getRichParagraphListByTextRange(selection)
if (paragraphs.isEmpty()) return
val removeUnorderedList = paragraphs.first().type is UnorderedList
paragraphs.forEach { paragraph ->
if (removeUnorderedList) {
removeUnorderedList(paragraph)
} else {
addUnorderedList(paragraph)
}
}
}

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

}

private fun addUnorderedList(paragraph: RichParagraph) {
if (paragraph.type is UnorderedList) return

val newType = UnorderedList()
Expand All @@ -571,19 +581,34 @@ class RichTextState internal constructor(

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

}

private fun removeUnorderedList(paragraph: RichParagraph) {
if (paragraph.type !is UnorderedList) return

resetParagraphType(paragraph = paragraph)
}

fun toggleOrderedList() {
val paragraph = getRichParagraphByTextIndex(selection.min - 1) ?: return
if (paragraph.type is OrderedList) removeOrderedList()
else addOrderedList()
val paragraphs = getRichParagraphListByTextRange(selection)
if (paragraphs.isEmpty()) return
val removeOrderedList = paragraphs.first().type is OrderedList
paragraphs.forEach { paragraph ->
if (removeOrderedList) {
removeOrderedList(paragraph)
} else {
addOrderedList(paragraph)
}
}
}

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

}

private fun addOrderedList(paragraph: RichParagraph) {
if (paragraph.type is OrderedList) return
val index = richParagraphList.indexOf(paragraph)
if (index == -1) return
Expand Down Expand Up @@ -617,6 +642,10 @@ class RichTextState internal constructor(

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

}

private fun removeOrderedList(paragraph: RichParagraph) {
if (paragraph.type !is OrderedList) return
val index = richParagraphList.indexOf(paragraph)
if (index == -1) return
Expand Down Expand Up @@ -2228,6 +2257,11 @@ class RichTextState internal constructor(
private fun getRichParagraphListByTextRange(searchTextRange: TextRange): List<RichParagraph> {
if (singleParagraphMode) return richParagraphList.toList()

if (searchTextRange.collapsed) {
val paragraph = getRichParagraphByTextIndex(searchTextRange.min - 1) ?: return listOf()
return listOf(paragraph)
}

var index = 0
val richParagraphList = mutableListOf<RichParagraph>()
this.richParagraphList.fastForEachIndexed { paragraphIndex, richParagraphStyle ->
Expand Down
Loading