Skip to content

Commit

Permalink
Merge pull request #182 from MohamedRejeb/1.x
Browse files Browse the repository at this point in the history
Add abstraction to ParagraphType
  • Loading branch information
MohamedRejeb authored Jan 26, 2024
2 parents 6d7bb36 + a7bd665 commit 6d0230c
Show file tree
Hide file tree
Showing 19 changed files with 357 additions and 207 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.paragraph.RichParagraph
import com.mohamedrejeb.richeditor.utils.customMerge
import com.mohamedrejeb.richeditor.utils.fastForEach
import com.mohamedrejeb.richeditor.utils.isSpecifiedFieldsEquals
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,21 @@ import com.mohamedrejeb.richeditor.utils.getBoundingBoxes
internal interface RichSpanStyle {
val spanStyle: (RichTextConfig) -> SpanStyle

val data: MutableMap<String, String>

/**
* If true, the user can add new text in the edges of the span,
* For example, if the span is "Hello" and the user adds "World" in the end, the span will be "Hello World"
* If false, the user can't add new text in the edges of the span,
* For example, if the span is a "Hello" link and the user adds "World" in the end, the "World" will be added in a separate a span,
*
* Default value is true
*/
val acceptNewTextInTheEdges: Boolean
get() = true

fun DrawScope.drawCustomStyle(
layoutResult: TextLayoutResult,
textRange: TextRange,
richTextConfig: RichTextConfig,
topPadding: Float = 0f,
startPadding: Float = 0f,
) {}
)

class Link(
val url: String,
Expand All @@ -50,10 +45,16 @@ internal interface RichSpanStyle {
)
}

override val data: MutableMap<String, String> = mutableMapOf(
"url" to url,
)
override val acceptNewTextInTheEdges: Boolean = false
override fun DrawScope.drawCustomStyle(
layoutResult: TextLayoutResult,
textRange: TextRange,
richTextConfig: RichTextConfig,
topPadding: Float,
startPadding: Float
) = Unit

override val acceptNewTextInTheEdges: Boolean =
false
}

class Code(
Expand All @@ -66,7 +67,6 @@ internal interface RichSpanStyle {
color = it.codeColor,
)
}
override val data: MutableMap<String, String> = mutableMapOf()

override fun DrawScope.drawCustomStyle(
layoutResult: TextLayoutResult,
Expand Down Expand Up @@ -114,11 +114,25 @@ internal interface RichSpanStyle {
)
}
}

override val acceptNewTextInTheEdges: Boolean =
true
}

object Default : RichSpanStyle {
override val spanStyle: (RichTextConfig) -> SpanStyle = { SpanStyle() }
override val data: MutableMap<String, String> = mutableMapOf()
override val spanStyle: (RichTextConfig) -> SpanStyle =
{ SpanStyle() }

override fun DrawScope.drawCustomStyle(
layoutResult: TextLayoutResult,
textRange: TextRange,
richTextConfig: RichTextConfig,
topPadding: Float,
startPadding: Float
) = Unit

override val acceptNewTextInTheEdges: Boolean =
true
}

companion object {
Expand Down
Loading

0 comments on commit 6d0230c

Please sign in to comment.