Skip to content

Commit

Permalink
Merge pull request #316 from MohamedRejeb/1.x
Browse files Browse the repository at this point in the history
Improve HTML import
  • Loading branch information
MohamedRejeb authored Aug 3, 2024
2 parents 80545e1 + 13fa5aa commit 0fd3220
Show file tree
Hide file tree
Showing 20 changed files with 267 additions and 144 deletions.
4 changes: 0 additions & 4 deletions richeditor-compose/api/android/richeditor-compose.api
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,6 @@ public final class com/mohamedrejeb/richeditor/utils/FloatUtilsKt {
public static final fun maxDecimals (FI)F
}

public final class com/mohamedrejeb/richeditor/utils/ListExtKt {
public static final fun fastForEachIndexed (Ljava/util/List;Lkotlin/jvm/functions/Function2;)V
}

public final class com/mohamedrejeb/richeditor/utils/TextDecorationExtKt {
public static final fun minus (Landroidx/compose/ui/text/style/TextDecoration;Landroidx/compose/ui/text/style/TextDecoration;)Landroidx/compose/ui/text/style/TextDecoration;
}
Expand Down
4 changes: 0 additions & 4 deletions richeditor-compose/api/desktop/richeditor-compose.api
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,6 @@ public final class com/mohamedrejeb/richeditor/utils/FloatUtilsKt {
public static final fun maxDecimals (FI)F
}

public final class com/mohamedrejeb/richeditor/utils/ListExtKt {
public static final fun fastForEachIndexed (Ljava/util/List;Lkotlin/jvm/functions/Function2;)V
}

public final class com/mohamedrejeb/richeditor/utils/TextDecorationExtKt {
public static final fun minus (Landroidx/compose/ui/text/style/TextDecoration;Landroidx/compose/ui/text/style/TextDecoration;)Landroidx/compose/ui/text/style/TextDecoration;
}
Expand Down
1 change: 0 additions & 1 deletion richeditor-compose/api/richeditor-compose.klib.api
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,3 @@ final fun com.mohamedrejeb.richeditor.ui.material3/RichTextEditor(com.mohamedrej
final fun com.mohamedrejeb.richeditor.ui/BasicRichText(com.mohamedrejeb.richeditor.model/RichTextState, androidx.compose.ui/Modifier?, androidx.compose.ui.text/TextStyle?, kotlin/Function1<androidx.compose.ui.text/TextLayoutResult, kotlin/Unit>?, androidx.compose.ui.text.style/TextOverflow, kotlin/Boolean, kotlin/Int, kotlin/Int, kotlin.collections/Map<kotlin/String, androidx.compose.foundation.text/InlineTextContent>?, com.mohamedrejeb.richeditor.model/ImageLoader?, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int) // com.mohamedrejeb.richeditor.ui/BasicRichText|BasicRichText(com.mohamedrejeb.richeditor.model.RichTextState;androidx.compose.ui.Modifier?;androidx.compose.ui.text.TextStyle?;kotlin.Function1<androidx.compose.ui.text.TextLayoutResult,kotlin.Unit>?;androidx.compose.ui.text.style.TextOverflow;kotlin.Boolean;kotlin.Int;kotlin.Int;kotlin.collections.Map<kotlin.String,androidx.compose.foundation.text.InlineTextContent>?;com.mohamedrejeb.richeditor.model.ImageLoader?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){}[0]
final fun com.mohamedrejeb.richeditor.ui/BasicRichTextEditor(com.mohamedrejeb.richeditor.model/RichTextState, androidx.compose.ui/Modifier?, kotlin/Boolean, kotlin/Boolean, androidx.compose.ui.text/TextStyle?, androidx.compose.foundation.text/KeyboardOptions?, androidx.compose.foundation.text/KeyboardActions?, kotlin/Boolean, kotlin/Boolean, kotlin/Int, kotlin/Int, kotlin/Int, kotlin/Function1<androidx.compose.ui.text/TextLayoutResult, kotlin/Unit>?, androidx.compose.foundation.interaction/MutableInteractionSource?, androidx.compose.ui.graphics/Brush?, kotlin/Function3<kotlin/Function2<androidx.compose.runtime/Composer, kotlin/Int, kotlin/Unit>, androidx.compose.runtime/Composer, kotlin/Int, kotlin/Unit>?, androidx.compose.foundation.layout/PaddingValues, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int, kotlin/Int) // com.mohamedrejeb.richeditor.ui/BasicRichTextEditor|BasicRichTextEditor(com.mohamedrejeb.richeditor.model.RichTextState;androidx.compose.ui.Modifier?;kotlin.Boolean;kotlin.Boolean;androidx.compose.ui.text.TextStyle?;androidx.compose.foundation.text.KeyboardOptions?;androidx.compose.foundation.text.KeyboardActions?;kotlin.Boolean;kotlin.Boolean;kotlin.Int;kotlin.Int;kotlin.Int;kotlin.Function1<androidx.compose.ui.text.TextLayoutResult,kotlin.Unit>?;androidx.compose.foundation.interaction.MutableInteractionSource?;androidx.compose.ui.graphics.Brush?;kotlin.Function3<kotlin.Function2<androidx.compose.runtime.Composer,kotlin.Int,kotlin.Unit>,androidx.compose.runtime.Composer,kotlin.Int,kotlin.Unit>?;androidx.compose.foundation.layout.PaddingValues;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int;kotlin.Int){}[0]
final fun com.mohamedrejeb.richeditor.ui/BasicRichTextEditor(com.mohamedrejeb.richeditor.model/RichTextState, androidx.compose.ui/Modifier?, kotlin/Boolean, kotlin/Boolean, androidx.compose.ui.text/TextStyle?, androidx.compose.foundation.text/KeyboardOptions?, androidx.compose.foundation.text/KeyboardActions?, kotlin/Boolean, kotlin/Int, kotlin/Int, kotlin/Int, kotlin/Function1<androidx.compose.ui.text/TextLayoutResult, kotlin/Unit>?, androidx.compose.foundation.interaction/MutableInteractionSource?, androidx.compose.ui.graphics/Brush?, kotlin/Function3<kotlin/Function2<androidx.compose.runtime/Composer, kotlin/Int, kotlin/Unit>, androidx.compose.runtime/Composer, kotlin/Int, kotlin/Unit>?, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int, kotlin/Int) // com.mohamedrejeb.richeditor.ui/BasicRichTextEditor|BasicRichTextEditor(com.mohamedrejeb.richeditor.model.RichTextState;androidx.compose.ui.Modifier?;kotlin.Boolean;kotlin.Boolean;androidx.compose.ui.text.TextStyle?;androidx.compose.foundation.text.KeyboardOptions?;androidx.compose.foundation.text.KeyboardActions?;kotlin.Boolean;kotlin.Int;kotlin.Int;kotlin.Int;kotlin.Function1<androidx.compose.ui.text.TextLayoutResult,kotlin.Unit>?;androidx.compose.foundation.interaction.MutableInteractionSource?;androidx.compose.ui.graphics.Brush?;kotlin.Function3<kotlin.Function2<androidx.compose.runtime.Composer,kotlin.Int,kotlin.Unit>,androidx.compose.runtime.Composer,kotlin.Int,kotlin.Unit>?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int;kotlin.Int){}[0]
final inline fun <#A: kotlin/Any?> (kotlin.collections/List<#A>).com.mohamedrejeb.richeditor.utils/fastForEachIndexed(kotlin/Function2<kotlin/Int, #A, kotlin/Unit>) // com.mohamedrejeb.richeditor.utils/fastForEachIndexed|fastForEachIndexed@kotlin.collections.List<0:0>(kotlin.Function2<kotlin.Int,0:0,kotlin.Unit>){0§<kotlin.Any?>}[0]
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import androidx.compose.ui.input.pointer.PointerEventTimeoutCancellationExceptio
import androidx.compose.ui.input.pointer.PointerInputChange
import androidx.compose.ui.input.pointer.PointerInputScope
import androidx.compose.ui.platform.ViewConfiguration
import com.mohamedrejeb.richeditor.utils.fastAny
import com.mohamedrejeb.richeditor.utils.fastForEach
import androidx.compose.ui.util.fastAny
import androidx.compose.ui.util.fastForEach
import kotlinx.coroutines.coroutineScope

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package com.mohamedrejeb.richeditor.model

import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.text.TextRange
import androidx.compose.ui.util.fastForEach
import androidx.compose.ui.util.fastForEachIndexed
import androidx.compose.ui.util.fastForEachReversed
import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi
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 Expand Up @@ -172,7 +174,7 @@ internal class RichSpan(
*
* @return True if the rich span is empty, false otherwise
*/
fun isEmpty(): Boolean = text.isEmpty() && isChildrenEmpty()
fun isEmpty(): Boolean = text.isEmpty() && isChildrenEmpty() && richSpanStyle !is RichSpanStyle.Image

/**
* Check if the rich span is blank.
Expand Down Expand Up @@ -441,6 +443,21 @@ internal class RichSpan(
}
}

fun removeEmptyChildren() {
val toRemoveIndices = mutableListOf<Int>()

children.fastForEachIndexed { i, richSpan ->
if (richSpan.isEmpty())
toRemoveIndices.add(i)
else
richSpan.removeEmptyChildren()
}

toRemoveIndices.fastForEachReversed {
children.removeAt(it)
}
}

fun copy(
newParagraph: RichParagraph = paragraph,
): RichSpan {
Expand Down Expand Up @@ -480,6 +497,6 @@ internal class RichSpan(
)

override fun toString(): String {
return "richSpan(text='$text', textRange=$textRange, fullTextRange=$fullTextRange)"
return "richSpan(text='$text', textRange=$textRange, fullTextRange=$fullTextRange), richSpanStyle=$richSpanStyle)"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package com.mohamedrejeb.richeditor.model

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.text.InlineTextContent
import androidx.compose.foundation.text.appendInlineContent
import androidx.compose.ui.Modifier
Expand All @@ -16,10 +14,9 @@ import androidx.compose.ui.graphics.drawscope.Stroke
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.text.*
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.compose.ui.util.fastForEachIndexed
import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi
import com.mohamedrejeb.richeditor.utils.fastForEachIndexed
import com.mohamedrejeb.richeditor.utils.getBoundingBoxes

@ExperimentalRichTextApi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.text.style.TextDecoration
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.sp
import androidx.compose.ui.util.fastFirstOrNull
import androidx.compose.ui.util.fastForEach
import androidx.compose.ui.util.fastForEachIndexed
import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi
import com.mohamedrejeb.richeditor.paragraph.RichParagraph
import com.mohamedrejeb.richeditor.paragraph.type.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package com.mohamedrejeb.richeditor.paragraph

import androidx.compose.ui.text.ParagraphStyle
import androidx.compose.ui.text.TextRange
import androidx.compose.ui.util.fastForEach
import androidx.compose.ui.util.fastForEachIndexed
import androidx.compose.ui.util.fastForEachReversed
import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi
import com.mohamedrejeb.richeditor.model.RichSpan
import com.mohamedrejeb.richeditor.paragraph.type.DefaultParagraph
import com.mohamedrejeb.richeditor.paragraph.type.ParagraphType
import com.mohamedrejeb.richeditor.paragraph.type.ParagraphType.Companion.startText
import com.mohamedrejeb.richeditor.ui.test.getRichTextStyleTreeRepresentation
import com.mohamedrejeb.richeditor.utils.fastForEach
import com.mohamedrejeb.richeditor.utils.fastForEachIndexed

internal class RichParagraph(
val key: Int = 0,
Expand Down Expand Up @@ -180,6 +181,21 @@ internal class RichParagraph(
}
}

fun removeEmptyChildren() {
val toRemoveIndices = mutableListOf<Int>()

children.fastForEachIndexed { index, richSpan ->
if (richSpan.isEmpty())
toRemoveIndices.add(index)
else
richSpan.removeEmptyChildren()
}

toRemoveIndices.fastForEachReversed {
children.removeAt(it)
}
}

fun copy(): RichParagraph {
val newParagraph = RichParagraph(
paragraphStyle = paragraphStyle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ internal fun removeHtmlTextExtraSpaces(input: String, trimStart: Boolean = false
.replace('\n', ' ')
.replace("\\s+".toRegex(), " ")
.let {
if (trimStart) it.trimStart()
else it
if (trimStart)
it.trimStart()
else
it
}
}

Expand Down Expand Up @@ -42,6 +44,7 @@ internal val htmlBlockElements = setOf(
* HTML elements that should be skipped.
*/
internal val skippedHtmlElements = setOf(
"html",
"head",
"meta",
"title",
Expand Down
Loading

0 comments on commit 0fd3220

Please # to comment.