Skip to content

Commit

Permalink
Update docs (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedRejeb authored May 23, 2024
1 parent c1388c8 commit b3f3544
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 48 deletions.
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,11 @@ val isUnorderedList = richTextState.isUnorderedList
Some of the rich text editor's features can be customized, such as the color of the links and the code blocks.

```kotlin
richTextState.setConfig(
linkColor = Color.Blue,
linkTextDecoration = TextDecoration.Underline,
codeColor = Color.Yellow,
codeBackgroundColor = Color.Transparent,
codeStrokeColor = Color.LightGray,
)
richTextState.config.linkColor = Color.Blue
richTextState.config.linkTextDecoration = TextDecoration.Underline
richTextState.config.codeSpanColor = Color.Yellow
richTextState.config.codeSpanBackgroundColor = Color.Transparent
richTextState.config.codeSpanStrokeColor = Color.LightGray
```

#### HTML import and export
Expand Down
6 changes: 3 additions & 3 deletions docs/code_blocks.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Code Blocks
# Code Spans

To add code blocks, `RichTextState` provides `toggleCodeSpan` method:
To add code spans, `RichTextState` provides `toggleCodeSpan` method:

```kotlin
// Toggle code span.
richTextState.toggleCodeSpan()
```

To get if the current selection is a code block, use `RichTextState.isCodeSpan`:
To get if the current selection is a code span, use `RichTextState.isCodeSpan`:

```kotlin
// Get if the current selection is a code span.
Expand Down
12 changes: 5 additions & 7 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,11 @@ val isUnorderedList = richTextState.isUnorderedList
Some of the rich text editor's features can be customized, such as the color of the links and the code blocks.

```kotlin
richTextState.setConfig(
linkColor = Color.Blue,
linkTextDecoration = TextDecoration.Underline,
codeColor = Color.Yellow,
codeBackgroundColor = Color.Transparent,
codeStrokeColor = Color.LightGray,
)
richTextState.config.linkColor = Color.Blue
richTextState.config.linkTextDecoration = TextDecoration.Underline
richTextState.config.codeSpanColor = Color.Yellow
richTextState.config.codeSpanBackgroundColor = Color.Transparent
richTextState.config.codeSpanStrokeColor = Color.LightGray
```

#### HTML import and export
Expand Down
12 changes: 5 additions & 7 deletions docs/rich_text_state.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ RichTextEditor(
Some of the rich text editor's features can be customized, such as the color of the links and the code blocks.

```kotlin
richTextState.setConfig(
linkColor = Color.Blue,
linkTextDecoration = TextDecoration.Underline,
codeColor = Color.Yellow,
codeBackgroundColor = Color.Transparent,
codeStrokeColor = Color.LightGray,
)
richTextState.config.linkColor = Color.Blue
richTextState.config.linkTextDecoration = TextDecoration.Underline
richTextState.config.codeSpanColor = Color.Yellow
richTextState.config.codeSpanBackgroundColor = Color.Transparent
richTextState.config.codeSpanStrokeColor = Color.LightGray
```

### Changing the editor's selection
Expand Down
16 changes: 13 additions & 3 deletions docs/span_style.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,26 @@ richTextState.toggleSpanStyle(SpanStyle(fontWeight = FontWeight.Bold))
// Add a span style.
richTextState.addSpanStyle(SpanStyle(fontWeight = FontWeight.Bold))

// Add a span style for a specific range.
richTextState.addSpanStyle(SpanStyle(fontWeight = FontWeight.Bold), TextRange(0, 5))

// Remove a span style.
richTextState.removeSpanStyle(SpanStyle(fontWeight = FontWeight.Bold))

// Remove a span style for a specific range.
richTextState.removeSpanStyle(SpanStyle(fontWeight = FontWeight.Bold), TextRange(0, 5))
```

To get the current span style of the selection, use `RichTextState.currentSpanStyle`:

```kotlin
// Get the current span style.
val currentSpanStyle = richTextState.currentSpanStyle
val isBold = currentSpanStyle.fontWeight = FontWeight.Bold
val isItalic = currentSpanStyle.fontStyle = FontStyle.Italic
val isUnderline = currentSpanStyle.textDecoration = TextDecoration.Underline
val isBold = currentSpanStyle.fontWeight == FontWeight.Bold
val isItalic = currentSpanStyle.fontStyle == FontStyle.Italic
val isUnderline = currentSpanStyle.textDecoration == TextDecoration.Underline

// Get the span style for a specific range.
val spanStyle = richTextState.getSpanStyle(TextRange(0, 5))
val isBold = spanStyle.fontWeight == FontWeight.Bold
```
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ class RichTextState internal constructor(
}

@Deprecated(
message = "Use isCodeSpan instead",
replaceWith = ReplaceWith("isCodeSpan"),
message = "Use config instead",
replaceWith = ReplaceWith("config"),
level = DeprecationLevel.WARNING,
)
fun setConfig(
Expand Down Expand Up @@ -239,7 +239,7 @@ class RichTextState internal constructor(
* @param textRange the text range.
* @return the [SpanStyle] of the text at the specified text range.
*/
fun getSpanStyleByTextRange(textRange: TextRange): SpanStyle =
fun getSpanStyle(textRange: TextRange): SpanStyle =
if (textRange.collapsed) {
val richSpan = getRichSpanByTextIndex(textIndex = textRange.min - 1)

Expand All @@ -261,7 +261,7 @@ class RichTextState internal constructor(
* @param textRange the text range.
* @return the [RichSpanStyle] of the text at the specified text range.
*/
fun getRichSpanStyleByTextRange(textRange: TextRange): RichSpanStyle =
fun getRichSpanStyle(textRange: TextRange): RichSpanStyle =
if (textRange.collapsed) {
val richSpan = getRichSpanByTextIndex(textIndex = textRange.min - 1)

Expand All @@ -283,7 +283,7 @@ class RichTextState internal constructor(
* @param textRange the text range.
* @return the [ParagraphStyle] of the text at the specified text range.
*/
fun getParagraphStyleByTextRange(textRange: TextRange): ParagraphStyle =
fun getParagraphStyle(textRange: TextRange): ParagraphStyle =
if (textRange.collapsed) {
val richParagraph = getRichParagraphByTextIndex(textIndex = textRange.min - 1)

Expand All @@ -305,7 +305,7 @@ class RichTextState internal constructor(
* @param textRange the text range.
* @return the [ParagraphType] of the text at the specified text range.
*/
internal fun getParagraphTypeByTextRange(textRange: TextRange): ParagraphType =
internal fun getParagraphType(textRange: TextRange): ParagraphType =
if (textRange.collapsed) {
val richParagraph = getRichParagraphByTextIndex(textIndex = textRange.min - 1)

Expand Down Expand Up @@ -2766,18 +2766,18 @@ class RichTextState internal constructor(
*
* @return A copy of this [RichTextState].
*/
@OptIn(ExperimentalRichTextApi::class)
fun copy(): RichTextState {
val richParagraphList = richParagraphList.map { it.copy() }
val richTextState = RichTextState(richParagraphList)
richTextState.updateTextFieldValue(textFieldValue)
richTextState.setConfig(
linkColor = config.linkColor,
linkTextDecoration = config.linkTextDecoration,
codeColor = config.codeSpanColor,
codeBackgroundColor = config.codeSpanBackgroundColor,
codeStrokeColor = config.codeSpanStrokeColor,
)
richTextState.config.linkColor = config.linkColor
richTextState.config.linkTextDecoration = config.linkTextDecoration
richTextState.config.codeSpanColor = config.codeSpanColor
richTextState.config.codeSpanBackgroundColor = config.codeSpanBackgroundColor
richTextState.config.codeSpanStrokeColor = config.codeSpanStrokeColor
richTextState.config.listIndent = config.listIndent
richTextState.config.preserveStyleOnEmptyLine = config.preserveStyleOnEmptyLine

return richTextState
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,11 @@ fun SlackDemoContent() {
val openLinkDialog = remember { mutableStateOf(false) }

LaunchedEffect(Unit) {
richTextState.setConfig(
linkColor = Color(0xFF1d9bd1),
linkTextDecoration = TextDecoration.None,
codeColor = Color(0xFFd7882d),
codeBackgroundColor = Color.Transparent,
codeStrokeColor = Color(0xFF494b4d),
)
richTextState.config.linkColor = Color(0xFF1d9bd1)
richTextState.config.linkTextDecoration = TextDecoration.None
richTextState.config.codeSpanColor = Color(0xFFd7882d)
richTextState.config.codeSpanBackgroundColor = Color.Transparent
richTextState.config.codeSpanStrokeColor = Color(0xFF494b4d)
}

Box(
Expand Down

0 comments on commit b3f3544

Please sign in to comment.