Skip to content

Commit

Permalink
Merge pull request #371 from MohamedRejeb/1.x
Browse files Browse the repository at this point in the history
Support String Operations on Rich Text while retaining styles
  • Loading branch information
MohamedRejeb authored Sep 30, 2024
2 parents 1f48669 + 3da7db9 commit 0e87b44
Show file tree
Hide file tree
Showing 6 changed files with 375 additions and 123 deletions.
24 changes: 24 additions & 0 deletions docs/rich_text_state.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,28 @@ The editor's selection can be changed using the `RichTextState.selection` proper

```kotlin
richTextState.selection = TextRange(0, 5)
```

### Performing string operations on rich text

The `RichTextState` class provides a set of functions to perform string operations on the rich text while preserving the styles.

```kotlin
// Insert text at custom posiotn.
richTextState.addTextAtIndex(5, "Hello")

// Insert text after the current selection.
richTextState.addTextAfterSelection("Hello")

// Remove text range.
richTextState.removeTextRange(TextRange(0, 5))

// Remove selected text.
richTextState.removeSelectedText()

// Replace text range.
richTextState.replaceTextRange(TextRange(0, 5), "Hello")

// Replace selected text.
richTextState.replaceSelectedText("Hello")
```
5 changes: 5 additions & 0 deletions richeditor-compose/api/android/richeditor-compose.api
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ public final class com/mohamedrejeb/richeditor/model/RichTextState {
public final fun addRichSpan-FDrldGo (Lcom/mohamedrejeb/richeditor/model/RichSpanStyle;J)V
public final fun addSpanStyle (Landroidx/compose/ui/text/SpanStyle;)V
public final fun addSpanStyle-FDrldGo (Landroidx/compose/ui/text/SpanStyle;J)V
public final fun addTextAfterSelection (Ljava/lang/String;)V
public final fun addTextAtIndex (ILjava/lang/String;)V
public final fun addUnorderedList ()V
public final fun clear ()V
public final fun clearRichSpans ()V
Expand Down Expand Up @@ -167,10 +169,13 @@ public final class com/mohamedrejeb/richeditor/model/RichTextState {
public final fun removeParagraphStyle (Landroidx/compose/ui/text/ParagraphStyle;)V
public final fun removeRichSpan (Lcom/mohamedrejeb/richeditor/model/RichSpanStyle;)V
public final fun removeRichSpan-FDrldGo (Lcom/mohamedrejeb/richeditor/model/RichSpanStyle;J)V
public final fun removeSelectedText ()V
public final fun removeSpanStyle (Landroidx/compose/ui/text/SpanStyle;)V
public final fun removeSpanStyle-FDrldGo (Landroidx/compose/ui/text/SpanStyle;J)V
public final fun removeTextRange-5zc-tL8 (J)V
public final fun removeUnorderedList ()V
public final fun replaceSelectedText (Ljava/lang/String;)V
public final fun replaceTextRange-72CqOWE (JLjava/lang/String;)V
public final fun setConfig-kmsmbh4 (JLandroidx/compose/ui/text/style/TextDecoration;JJJI)V
public static synthetic fun setConfig-kmsmbh4$default (Lcom/mohamedrejeb/richeditor/model/RichTextState;JLandroidx/compose/ui/text/style/TextDecoration;JJJIILjava/lang/Object;)V
public final fun setHtml (Ljava/lang/String;)Lcom/mohamedrejeb/richeditor/model/RichTextState;
Expand Down
5 changes: 5 additions & 0 deletions richeditor-compose/api/desktop/richeditor-compose.api
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ public final class com/mohamedrejeb/richeditor/model/RichTextState {
public final fun addRichSpan-FDrldGo (Lcom/mohamedrejeb/richeditor/model/RichSpanStyle;J)V
public final fun addSpanStyle (Landroidx/compose/ui/text/SpanStyle;)V
public final fun addSpanStyle-FDrldGo (Landroidx/compose/ui/text/SpanStyle;J)V
public final fun addTextAfterSelection (Ljava/lang/String;)V
public final fun addTextAtIndex (ILjava/lang/String;)V
public final fun addUnorderedList ()V
public final fun clear ()V
public final fun clearRichSpans ()V
Expand Down Expand Up @@ -167,10 +169,13 @@ public final class com/mohamedrejeb/richeditor/model/RichTextState {
public final fun removeParagraphStyle (Landroidx/compose/ui/text/ParagraphStyle;)V
public final fun removeRichSpan (Lcom/mohamedrejeb/richeditor/model/RichSpanStyle;)V
public final fun removeRichSpan-FDrldGo (Lcom/mohamedrejeb/richeditor/model/RichSpanStyle;J)V
public final fun removeSelectedText ()V
public final fun removeSpanStyle (Landroidx/compose/ui/text/SpanStyle;)V
public final fun removeSpanStyle-FDrldGo (Landroidx/compose/ui/text/SpanStyle;J)V
public final fun removeTextRange-5zc-tL8 (J)V
public final fun removeUnorderedList ()V
public final fun replaceSelectedText (Ljava/lang/String;)V
public final fun replaceTextRange-72CqOWE (JLjava/lang/String;)V
public final fun setConfig-kmsmbh4 (JLandroidx/compose/ui/text/style/TextDecoration;JJJI)V
public static synthetic fun setConfig-kmsmbh4$default (Lcom/mohamedrejeb/richeditor/model/RichTextState;JLandroidx/compose/ui/text/style/TextDecoration;JJJIILjava/lang/Object;)V
public final fun setHtml (Ljava/lang/String;)Lcom/mohamedrejeb/richeditor/model/RichTextState;
Expand Down
5 changes: 5 additions & 0 deletions richeditor-compose/api/richeditor-compose.klib.api
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ final class com.mohamedrejeb.richeditor.model/RichTextState { // com.mohamedreje
final fun addRichSpan(com.mohamedrejeb.richeditor.model/RichSpanStyle, androidx.compose.ui.text/TextRange) // com.mohamedrejeb.richeditor.model/RichTextState.addRichSpan|addRichSpan(com.mohamedrejeb.richeditor.model.RichSpanStyle;androidx.compose.ui.text.TextRange){}[0]
final fun addSpanStyle(androidx.compose.ui.text/SpanStyle) // com.mohamedrejeb.richeditor.model/RichTextState.addSpanStyle|addSpanStyle(androidx.compose.ui.text.SpanStyle){}[0]
final fun addSpanStyle(androidx.compose.ui.text/SpanStyle, androidx.compose.ui.text/TextRange) // com.mohamedrejeb.richeditor.model/RichTextState.addSpanStyle|addSpanStyle(androidx.compose.ui.text.SpanStyle;androidx.compose.ui.text.TextRange){}[0]
final fun addTextAfterSelection(kotlin/String) // com.mohamedrejeb.richeditor.model/RichTextState.addTextAfterSelection|addTextAfterSelection(kotlin.String){}[0]
final fun addTextAtIndex(kotlin/Int, kotlin/String) // com.mohamedrejeb.richeditor.model/RichTextState.addTextAtIndex|addTextAtIndex(kotlin.Int;kotlin.String){}[0]
final fun addUnorderedList() // com.mohamedrejeb.richeditor.model/RichTextState.addUnorderedList|addUnorderedList(){}[0]
final fun clear() // com.mohamedrejeb.richeditor.model/RichTextState.clear|clear(){}[0]
final fun clearRichSpans() // com.mohamedrejeb.richeditor.model/RichTextState.clearRichSpans|clearRichSpans(){}[0]
Expand All @@ -202,10 +204,13 @@ final class com.mohamedrejeb.richeditor.model/RichTextState { // com.mohamedreje
final fun removeParagraphStyle(androidx.compose.ui.text/ParagraphStyle) // com.mohamedrejeb.richeditor.model/RichTextState.removeParagraphStyle|removeParagraphStyle(androidx.compose.ui.text.ParagraphStyle){}[0]
final fun removeRichSpan(com.mohamedrejeb.richeditor.model/RichSpanStyle) // com.mohamedrejeb.richeditor.model/RichTextState.removeRichSpan|removeRichSpan(com.mohamedrejeb.richeditor.model.RichSpanStyle){}[0]
final fun removeRichSpan(com.mohamedrejeb.richeditor.model/RichSpanStyle, androidx.compose.ui.text/TextRange) // com.mohamedrejeb.richeditor.model/RichTextState.removeRichSpan|removeRichSpan(com.mohamedrejeb.richeditor.model.RichSpanStyle;androidx.compose.ui.text.TextRange){}[0]
final fun removeSelectedText() // com.mohamedrejeb.richeditor.model/RichTextState.removeSelectedText|removeSelectedText(){}[0]
final fun removeSpanStyle(androidx.compose.ui.text/SpanStyle) // com.mohamedrejeb.richeditor.model/RichTextState.removeSpanStyle|removeSpanStyle(androidx.compose.ui.text.SpanStyle){}[0]
final fun removeSpanStyle(androidx.compose.ui.text/SpanStyle, androidx.compose.ui.text/TextRange) // com.mohamedrejeb.richeditor.model/RichTextState.removeSpanStyle|removeSpanStyle(androidx.compose.ui.text.SpanStyle;androidx.compose.ui.text.TextRange){}[0]
final fun removeTextRange(androidx.compose.ui.text/TextRange) // com.mohamedrejeb.richeditor.model/RichTextState.removeTextRange|removeTextRange(androidx.compose.ui.text.TextRange){}[0]
final fun removeUnorderedList() // com.mohamedrejeb.richeditor.model/RichTextState.removeUnorderedList|removeUnorderedList(){}[0]
final fun replaceSelectedText(kotlin/String) // com.mohamedrejeb.richeditor.model/RichTextState.replaceSelectedText|replaceSelectedText(kotlin.String){}[0]
final fun replaceTextRange(androidx.compose.ui.text/TextRange, kotlin/String) // com.mohamedrejeb.richeditor.model/RichTextState.replaceTextRange|replaceTextRange(androidx.compose.ui.text.TextRange;kotlin.String){}[0]
final fun setConfig(androidx.compose.ui.graphics/Color = ..., androidx.compose.ui.text.style/TextDecoration? = ..., androidx.compose.ui.graphics/Color = ..., androidx.compose.ui.graphics/Color = ..., androidx.compose.ui.graphics/Color = ..., kotlin/Int = ...) // com.mohamedrejeb.richeditor.model/RichTextState.setConfig|setConfig(androidx.compose.ui.graphics.Color;androidx.compose.ui.text.style.TextDecoration?;androidx.compose.ui.graphics.Color;androidx.compose.ui.graphics.Color;androidx.compose.ui.graphics.Color;kotlin.Int){}[0]
final fun setHtml(kotlin/String): com.mohamedrejeb.richeditor.model/RichTextState // com.mohamedrejeb.richeditor.model/RichTextState.setHtml|setHtml(kotlin.String){}[0]
final fun setMarkdown(kotlin/String): com.mohamedrejeb.richeditor.model/RichTextState // com.mohamedrejeb.richeditor.model/RichTextState.setMarkdown|setMarkdown(kotlin.String){}[0]
Expand Down
Loading

0 comments on commit 0e87b44

Please sign in to comment.