Skip to content

Commit

Permalink
Merge pull request #228 from MohamedRejeb/1.x
Browse files Browse the repository at this point in the history
Support add link to current selection
  • Loading branch information
MohamedRejeb authored Mar 31, 2024
2 parents ec09b91 + 05959d0 commit 2ef0305
Show file tree
Hide file tree
Showing 12 changed files with 369 additions and 262 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.mohamedrejeb.richeditor.model

import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.TextRange
import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi
import com.mohamedrejeb.richeditor.paragraph.RichParagraph
import com.mohamedrejeb.richeditor.utils.customMerge
import com.mohamedrejeb.richeditor.utils.fastForEach
Expand All @@ -10,6 +11,7 @@ import com.mohamedrejeb.richeditor.utils.isSpecifiedFieldsEquals
/**
* A rich span is a part of a rich paragraph.
*/
@OptIn(ExperimentalRichTextApi::class)
internal class RichSpan(
internal val key: Int? = null,
val children: MutableList<RichSpan> = mutableListOf(),
Expand Down Expand Up @@ -58,6 +60,18 @@ internal class RichSpan(
return spanStyle
}

val fullStyle: RichSpanStyle get() {
var style = this.style
var parent = this.parent

while (parent != null && style::class == RichSpanStyle.Default::class) {
style = parent.style
parent = parent.parent
}

return style
}

val before: RichSpan? get() {
val parentChildren = parent?.children ?: paragraph.children
val index = parentChildren.indexOf(this)
Expand Down Expand Up @@ -224,6 +238,7 @@ internal class RichSpan(
* @param offset The offset of the text range
* @return A pair of the offset and the rich span or null if the rich span is not found
*/
@OptIn(ExperimentalRichTextApi::class)
fun getRichSpanByTextIndex(
textIndex: Int,
offset: Int = 0,
Expand Down
Loading

0 comments on commit 2ef0305

Please sign in to comment.