Skip to content

Commit

Permalink
Merge branch 'main' into compose-160
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedRejeb authored Jan 28, 2024
2 parents 231136e + 3056965 commit 60e24aa
Show file tree
Hide file tree
Showing 21 changed files with 367 additions and 203 deletions.
3 changes: 3 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\=
org.gradle.caching=true
org.gradle.parallel=true

org.gradle.java.installations.auto-detect=true
org.gradle.java.installations.auto-download=true

#Kotlin
kotlin.code.style=official

Expand Down
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 60e24aa

Please sign in to comment.