-
-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
} | ||
|
||
private fun addUnorderedList(paragraph: RichParagraph) { | ||
if (paragraph.type is UnorderedList) return | ||
|
||
val newType = UnorderedList() | ||
|
@@ -571,19 +581,34 @@ class RichTextState internal constructor( | |
|
||
fun removeUnorderedList() { | ||
val paragraph = getRichParagraphByTextIndex(selection.min - 1) ?: return | ||
removeUnorderedList(paragraph) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 | ||
|
@@ -617,6 +642,10 @@ class RichTextState internal constructor( | |
|
||
fun removeOrderedList() { | ||
val paragraph = getRichParagraphByTextIndex(selection.min - 1) ?: return | ||
removeOrderedList(paragraph) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 | ||
|
@@ -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 -> | ||
|
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.
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