Skip to content

Commit 91c4849

Browse files
committed
Minor changes
1 parent e85286d commit 91c4849

File tree

4 files changed

+60
-44
lines changed

4 files changed

+60
-44
lines changed

editor/src/main/java/com/canopas/editor/ui/data/QuillTextManager.kt

+55-39
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ class QuillTextManager(quillSpan: QuillSpan) {
9898
getRichSpanListByTextRange(selection).distinct()
9999
}
100100

101+
updateSpanStyle(currentStyles)
102+
}
103+
104+
private fun updateSpanStyle(currentStyles: List<TextSpanStyle>) {
101105
val currentSpan = quillTextSpans.findLast {
102106
it.from <= selection.min - 2 && it.to >= selection.min - 2 && it.style.contains(
103107
TextSpanStyle.BulletStyle
@@ -395,48 +399,60 @@ class QuillTextManager(quillSpan: QuillSpan) {
395399
when {
396400
span.style == selectedStyles -> {
397401
if (isBulletStyle && newValue.getOrNull(startTypeIndex) == '\n') {
398-
if (newValue.getOrNull(startTypeIndex - 1) != '\n' && startTypeIndex == to) {
399-
quillTextSpans.add(
400-
index + 1,
401-
span.copy(
402-
from = startTypeIndex,
403-
to = startTypeIndex + typedCharsCount - 1,
404-
style = selectedStyles
405-
)
406-
)
407-
quillTextSpans.add(
408-
index + 2,
409-
span.copy(
410-
from = startTypeIndex + typedCharsCount,
411-
to = to + typedCharsCount,
412-
style = selectedStyles
413-
)
414-
)
415-
} else {
416-
if (startTypeIndex in (from + 1) until to) {
417-
val newSpans = mutableListOf<QuillTextSpan>()
418-
newSpans.add(span.copy(to = startTypeIndex - 1, style = styles))
419-
newSpans.add(
420-
span.copy(
421-
from = startTypeIndex,
422-
to = startTypeIndex + typedCharsCount - 1,
423-
style = selectedStyles
402+
if (newValue.getOrNull(startTypeIndex - 1) != '\n') {
403+
when (startTypeIndex) {
404+
to -> {
405+
quillTextSpans.add(
406+
index + 1,
407+
span.copy(
408+
from = startTypeIndex,
409+
to = startTypeIndex + typedCharsCount - 1,
410+
style = selectedStyles
411+
)
424412
)
425-
)
426-
newSpans.add(
427-
span.copy(
428-
from = startTypeIndex + typedCharsCount,
429-
to = to + typedCharsCount,
430-
style = styles
413+
quillTextSpans.add(
414+
index + 2,
415+
span.copy(
416+
from = startTypeIndex + typedCharsCount,
417+
to = to + typedCharsCount,
418+
style = selectedStyles
419+
)
431420
)
432-
)
433-
quillTextSpans.removeAt(index)
434-
quillTextSpans.addAll(index, newSpans)
435-
} else {
436-
val updatedSpan = span.copy(to = to + typedCharsCount, style = selectedStyles)
437-
quillTextSpans[index] = updatedSpan
438-
quillTextSpans.add(index + 1, updatedSpan)
421+
}
422+
423+
in (from + 1) until to -> {
424+
val newSpans = mutableListOf<QuillTextSpan>()
425+
newSpans.add(span.copy(to = startTypeIndex - 1, style = styles))
426+
newSpans.add(
427+
span.copy(
428+
from = startTypeIndex,
429+
to = startTypeIndex + typedCharsCount - 1,
430+
style = selectedStyles
431+
)
432+
)
433+
newSpans.add(
434+
span.copy(
435+
from = startTypeIndex + typedCharsCount,
436+
to = to + typedCharsCount,
437+
style = styles
438+
)
439+
)
440+
quillTextSpans.removeAt(index)
441+
quillTextSpans.addAll(index, newSpans)
442+
}
443+
444+
else -> {
445+
val updatedSpan =
446+
span.copy(to = to + typedCharsCount, style = selectedStyles)
447+
quillTextSpans[index] = updatedSpan
448+
quillTextSpans.add(index + 1, updatedSpan)
449+
}
439450
}
451+
} else {
452+
quillTextSpans[index] =
453+
span.copy(to = to + typedCharsCount, style = styles.filterNot {
454+
it == TextSpanStyle.BulletStyle
455+
})
440456
}
441457
} else {
442458
quillTextSpans[index] = span.copy(to = to + typedCharsCount, style = styles)

editor/src/test/java/com/canopas/editor/jsonparser/QuillRichTextStateAdapter.kt editor/src/test/java/com/canopas/editor/jsonparser/RichTextStateAdapter.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import com.google.gson.JsonSerializationContext
1111
import com.google.gson.JsonSerializer
1212
import java.lang.reflect.Type
1313

14-
class QuillRichTextStateAdapter : JsonSerializer<Span>, JsonDeserializer<Span> {
14+
class RichTextStateAdapter : JsonSerializer<Span>, JsonDeserializer<Span> {
1515
override fun serialize(
1616
src: Span?,
1717
typeOfSrc: Type?,

editor/src/test/java/com/canopas/editor/jsonparser/QuillJsonEditorParser.kt editor/src/test/java/com/canopas/editor/jsonparser/TestEditorParser.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import com.google.common.reflect.TypeToken
77
import com.google.gson.Gson
88
import com.google.gson.GsonBuilder
99

10-
class QuillJsonEditorParser : QuillEditorAdapter {
10+
class TestEditorParser : QuillEditorAdapter {
1111

1212
private val gson: Gson = GsonBuilder()
13-
.registerTypeAdapter(Span::class.java, QuillRichTextStateAdapter())
13+
.registerTypeAdapter(Span::class.java, RichTextStateAdapter())
1414
.create()
1515

1616
override fun encode(input: String): QuillSpan {

editor/src/test/java/com/canopas/editor/quilltextmanager/QuillTextManagerTest.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import android.text.Editable
55
import androidx.compose.ui.text.TextRange
66
import androidx.test.core.app.ApplicationProvider
77
import com.canopas.editor.MainCoroutineRule
8-
import com.canopas.editor.jsonparser.QuillJsonEditorParser
8+
import com.canopas.editor.jsonparser.TestEditorParser
99
import com.canopas.editor.ui.data.QuillEditorState
1010
import com.canopas.editor.ui.model.QuillTextSpan
1111
import com.canopas.editor.ui.utils.TextSpanStyle
@@ -35,7 +35,7 @@ class QuillTextManagerTest {
3535
editableInstance = Editable.Factory.getInstance()
3636
quillEditorState = QuillEditorState.Builder()
3737
.setInput(input)
38-
.adapter(QuillJsonEditorParser())
38+
.adapter(TestEditorParser())
3939
.build()
4040
sampleSpansListSize = quillEditorState.manager.quillTextSpans.size
4141
}

0 commit comments

Comments
 (0)