Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions app/src/main/java/com/anytypeio/anytype/ext/MarkupExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.anytypeio.anytype.core_models.Block.Content.Text.Mark
import com.anytypeio.anytype.core_models.ext.overlap
import com.anytypeio.anytype.core_models.misc.Overlap
import com.anytypeio.anytype.core_ui.common.Span
import com.anytypeio.anytype.core_ui.common.Underline
import com.anytypeio.anytype.core_ui.widgets.text.MentionSpan

fun Editable.extractMarks(): List<Mark> = getSpans(0, length, Span::class.java).mapNotNull { span ->
Expand Down Expand Up @@ -34,6 +35,10 @@ fun Editable.extractMarks(): List<Mark> = getSpans(0, length, Span::class.java).
range = getSpanStart(span)..getSpanEnd(span),
type = Mark.Type.BOLD
)
is Underline -> Mark(
range = getSpanStart(span)..getSpanEnd(span),
type = Mark.Type.UNDERLINE
)
is Span.Keyboard -> Mark(
range = getSpanStart(span)..getSpanEnd(span),
type = Mark.Type.KEYBOARD
Expand Down
17 changes: 17 additions & 0 deletions app/src/test/java/com/anytypeio/anytype/MarkupExtractTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,23 @@ class MarkupExtractTest {
)
}

@Test
fun `should extract underline span`() {
val mark = Markup.Mark.Underline(from = 2, to = 7)
stubMarkup("Synthetic text", mark)

val editable = markup.toSpannable(
textColor = 11,
context = context,
underlineHeight = 1f
)

assertEquals(
expected = listOf(Mark(range = mark.from..mark.to, type = Mark.Type.UNDERLINE)),
actual = editable.extractMarks()
)
}

@Test
fun `should extract strikethrough span`() {

Expand Down
Loading