Skip to content

Commit 0e87b44

Browse files
authored
Merge pull request #371 from MohamedRejeb/1.x
Support String Operations on Rich Text while retaining styles
2 parents 1f48669 + 3da7db9 commit 0e87b44

File tree

6 files changed

+375
-123
lines changed

6 files changed

+375
-123
lines changed

docs/rich_text_state.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,28 @@ The editor's selection can be changed using the `RichTextState.selection` proper
4444

4545
```kotlin
4646
richTextState.selection = TextRange(0, 5)
47+
```
48+
49+
### Performing string operations on rich text
50+
51+
The `RichTextState` class provides a set of functions to perform string operations on the rich text while preserving the styles.
52+
53+
```kotlin
54+
// Insert text at custom posiotn.
55+
richTextState.addTextAtIndex(5, "Hello")
56+
57+
// Insert text after the current selection.
58+
richTextState.addTextAfterSelection("Hello")
59+
60+
// Remove text range.
61+
richTextState.removeTextRange(TextRange(0, 5))
62+
63+
// Remove selected text.
64+
richTextState.removeSelectedText()
65+
66+
// Replace text range.
67+
richTextState.replaceTextRange(TextRange(0, 5), "Hello")
68+
69+
// Replace selected text.
70+
richTextState.replaceSelectedText("Hello")
4771
```

richeditor-compose/api/android/richeditor-compose.api

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ public final class com/mohamedrejeb/richeditor/model/RichTextState {
134134
public final fun addRichSpan-FDrldGo (Lcom/mohamedrejeb/richeditor/model/RichSpanStyle;J)V
135135
public final fun addSpanStyle (Landroidx/compose/ui/text/SpanStyle;)V
136136
public final fun addSpanStyle-FDrldGo (Landroidx/compose/ui/text/SpanStyle;J)V
137+
public final fun addTextAfterSelection (Ljava/lang/String;)V
138+
public final fun addTextAtIndex (ILjava/lang/String;)V
137139
public final fun addUnorderedList ()V
138140
public final fun clear ()V
139141
public final fun clearRichSpans ()V
@@ -167,10 +169,13 @@ public final class com/mohamedrejeb/richeditor/model/RichTextState {
167169
public final fun removeParagraphStyle (Landroidx/compose/ui/text/ParagraphStyle;)V
168170
public final fun removeRichSpan (Lcom/mohamedrejeb/richeditor/model/RichSpanStyle;)V
169171
public final fun removeRichSpan-FDrldGo (Lcom/mohamedrejeb/richeditor/model/RichSpanStyle;J)V
172+
public final fun removeSelectedText ()V
170173
public final fun removeSpanStyle (Landroidx/compose/ui/text/SpanStyle;)V
171174
public final fun removeSpanStyle-FDrldGo (Landroidx/compose/ui/text/SpanStyle;J)V
175+
public final fun removeTextRange-5zc-tL8 (J)V
172176
public final fun removeUnorderedList ()V
173177
public final fun replaceSelectedText (Ljava/lang/String;)V
178+
public final fun replaceTextRange-72CqOWE (JLjava/lang/String;)V
174179
public final fun setConfig-kmsmbh4 (JLandroidx/compose/ui/text/style/TextDecoration;JJJI)V
175180
public static synthetic fun setConfig-kmsmbh4$default (Lcom/mohamedrejeb/richeditor/model/RichTextState;JLandroidx/compose/ui/text/style/TextDecoration;JJJIILjava/lang/Object;)V
176181
public final fun setHtml (Ljava/lang/String;)Lcom/mohamedrejeb/richeditor/model/RichTextState;

richeditor-compose/api/desktop/richeditor-compose.api

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,8 @@ public final class com/mohamedrejeb/richeditor/model/RichTextState {
134134
public final fun addRichSpan-FDrldGo (Lcom/mohamedrejeb/richeditor/model/RichSpanStyle;J)V
135135
public final fun addSpanStyle (Landroidx/compose/ui/text/SpanStyle;)V
136136
public final fun addSpanStyle-FDrldGo (Landroidx/compose/ui/text/SpanStyle;J)V
137+
public final fun addTextAfterSelection (Ljava/lang/String;)V
138+
public final fun addTextAtIndex (ILjava/lang/String;)V
137139
public final fun addUnorderedList ()V
138140
public final fun clear ()V
139141
public final fun clearRichSpans ()V
@@ -167,10 +169,13 @@ public final class com/mohamedrejeb/richeditor/model/RichTextState {
167169
public final fun removeParagraphStyle (Landroidx/compose/ui/text/ParagraphStyle;)V
168170
public final fun removeRichSpan (Lcom/mohamedrejeb/richeditor/model/RichSpanStyle;)V
169171
public final fun removeRichSpan-FDrldGo (Lcom/mohamedrejeb/richeditor/model/RichSpanStyle;J)V
172+
public final fun removeSelectedText ()V
170173
public final fun removeSpanStyle (Landroidx/compose/ui/text/SpanStyle;)V
171174
public final fun removeSpanStyle-FDrldGo (Landroidx/compose/ui/text/SpanStyle;J)V
175+
public final fun removeTextRange-5zc-tL8 (J)V
172176
public final fun removeUnorderedList ()V
173177
public final fun replaceSelectedText (Ljava/lang/String;)V
178+
public final fun replaceTextRange-72CqOWE (JLjava/lang/String;)V
174179
public final fun setConfig-kmsmbh4 (JLandroidx/compose/ui/text/style/TextDecoration;JJJI)V
175180
public static synthetic fun setConfig-kmsmbh4$default (Lcom/mohamedrejeb/richeditor/model/RichTextState;JLandroidx/compose/ui/text/style/TextDecoration;JJJIILjava/lang/Object;)V
176181
public final fun setHtml (Ljava/lang/String;)Lcom/mohamedrejeb/richeditor/model/RichTextState;

richeditor-compose/api/richeditor-compose.klib.api

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ final class com.mohamedrejeb.richeditor.model/RichTextState { // com.mohamedreje
183183
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]
184184
final fun addSpanStyle(androidx.compose.ui.text/SpanStyle) // com.mohamedrejeb.richeditor.model/RichTextState.addSpanStyle|addSpanStyle(androidx.compose.ui.text.SpanStyle){}[0]
185185
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]
186+
final fun addTextAfterSelection(kotlin/String) // com.mohamedrejeb.richeditor.model/RichTextState.addTextAfterSelection|addTextAfterSelection(kotlin.String){}[0]
187+
final fun addTextAtIndex(kotlin/Int, kotlin/String) // com.mohamedrejeb.richeditor.model/RichTextState.addTextAtIndex|addTextAtIndex(kotlin.Int;kotlin.String){}[0]
186188
final fun addUnorderedList() // com.mohamedrejeb.richeditor.model/RichTextState.addUnorderedList|addUnorderedList(){}[0]
187189
final fun clear() // com.mohamedrejeb.richeditor.model/RichTextState.clear|clear(){}[0]
188190
final fun clearRichSpans() // com.mohamedrejeb.richeditor.model/RichTextState.clearRichSpans|clearRichSpans(){}[0]
@@ -202,10 +204,13 @@ final class com.mohamedrejeb.richeditor.model/RichTextState { // com.mohamedreje
202204
final fun removeParagraphStyle(androidx.compose.ui.text/ParagraphStyle) // com.mohamedrejeb.richeditor.model/RichTextState.removeParagraphStyle|removeParagraphStyle(androidx.compose.ui.text.ParagraphStyle){}[0]
203205
final fun removeRichSpan(com.mohamedrejeb.richeditor.model/RichSpanStyle) // com.mohamedrejeb.richeditor.model/RichTextState.removeRichSpan|removeRichSpan(com.mohamedrejeb.richeditor.model.RichSpanStyle){}[0]
204206
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]
207+
final fun removeSelectedText() // com.mohamedrejeb.richeditor.model/RichTextState.removeSelectedText|removeSelectedText(){}[0]
205208
final fun removeSpanStyle(androidx.compose.ui.text/SpanStyle) // com.mohamedrejeb.richeditor.model/RichTextState.removeSpanStyle|removeSpanStyle(androidx.compose.ui.text.SpanStyle){}[0]
206209
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]
210+
final fun removeTextRange(androidx.compose.ui.text/TextRange) // com.mohamedrejeb.richeditor.model/RichTextState.removeTextRange|removeTextRange(androidx.compose.ui.text.TextRange){}[0]
207211
final fun removeUnorderedList() // com.mohamedrejeb.richeditor.model/RichTextState.removeUnorderedList|removeUnorderedList(){}[0]
208212
final fun replaceSelectedText(kotlin/String) // com.mohamedrejeb.richeditor.model/RichTextState.replaceSelectedText|replaceSelectedText(kotlin.String){}[0]
213+
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]
209214
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]
210215
final fun setHtml(kotlin/String): com.mohamedrejeb.richeditor.model/RichTextState // com.mohamedrejeb.richeditor.model/RichTextState.setHtml|setHtml(kotlin.String){}[0]
211216
final fun setMarkdown(kotlin/String): com.mohamedrejeb.richeditor.model/RichTextState // com.mohamedrejeb.richeditor.model/RichTextState.setMarkdown|setMarkdown(kotlin.String){}[0]

0 commit comments

Comments
 (0)