From 848a06ac82985b67efdb3454c829dc7b3d7cd4a4 Mon Sep 17 00:00:00 2001
From: MohamedRejeb Before After Before After a a Before> {
+ if (lines.isEmpty()) return emptyList()
+ val clean = lines.map { it.removeSuffix("\r") }
+ val tokens = tokenize(clean.joinToString("\n"), language)
+ var lineStart = 0
+ var next = 0
+ return clean.map { line ->
+ val lineEnd = lineStart + line.length
+ val lineTokens = ArrayList
is content the author asked for, so stop there.
+ while (
+ richParagraphList.lastIndex !in brParagraphIndices &&
+ richParagraphList.lastOrNull()?.let { it.isBlank() && it.type is DefaultParagraph } == true
+ )
richParagraphList.removeAt(richParagraphList.lastIndex)
richParagraphList.addAll(codeBlockOf(language, lines))
// Text after the block must start a paragraph of its own, never join the last code line.
@@ -436,7 +440,8 @@ internal object RichTextStateMarkdownParser : RichTextStateParser
")
useLineBreak = isBlank
@@ -535,7 +541,8 @@ internal object RichTextStateMarkdownParser : RichTextStateParser
line is an HTML block that would run on into the fence without a blank line.
+ if ((!isBlank || isLineBreak) && nextParagraph.type is CodeBlock) {
builder.appendLine()
}
}
diff --git a/richeditor-compose/src/commonTest/kotlin/com/mohamedrejeb/richeditor/parser/markdown/CodeBlockMarkdownTest.kt b/richeditor-compose/src/commonTest/kotlin/com/mohamedrejeb/richeditor/parser/markdown/CodeBlockMarkdownTest.kt
index 4ca179a4..d7a49845 100644
--- a/richeditor-compose/src/commonTest/kotlin/com/mohamedrejeb/richeditor/parser/markdown/CodeBlockMarkdownTest.kt
+++ b/richeditor-compose/src/commonTest/kotlin/com/mohamedrejeb/richeditor/parser/markdown/CodeBlockMarkdownTest.kt
@@ -1,8 +1,11 @@
package com.mohamedrejeb.richeditor.parser.markdown
import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi
+import com.mohamedrejeb.richeditor.model.RichSpan
import com.mohamedrejeb.richeditor.model.RichTextState
+import com.mohamedrejeb.richeditor.paragraph.RichParagraph
import com.mohamedrejeb.richeditor.paragraph.codeBlockGroups
+import com.mohamedrejeb.richeditor.paragraph.codeBlockOf
import com.mohamedrejeb.richeditor.paragraph.plainText
import com.mohamedrejeb.richeditor.paragraph.type.CodeBlock
import com.mohamedrejeb.richeditor.paragraph.type.DefaultParagraph
@@ -67,6 +70,29 @@ class CodeBlockMarkdownTest {
assertEquals(listOf("Before", "b", "After"), state.richParagraphList.map { it.plainText() })
}
+ @Test
+ fun `a br blank line before a block is kept`() {
+ val state = stateOf("a
\n\n```\nb\n```")
+ assertEquals(listOf("a", "", "b"), state.richParagraphList.map { it.plainText() })
+ assertTrue(state.richParagraphList[1].type is DefaultParagraph)
+ assertTrue(state.richParagraphList[2].type is CodeBlock)
+ }
+
+ @Test
+ fun `blank code lines between two br lines are kept`() {
+ val state = stateOf("a
\n\n```\n\n\n```\n
")
+ assertEquals(listOf("", ""), state.codeLines())
+ }
+
+ @Test
+ fun `two blank paragraphs before a block survive an export and import`() {
+ val text = RichParagraph().also { it.children.add(RichSpan(paragraph = it, text = "a")) }
+ val paragraphs = listOf(text, RichParagraph(), RichParagraph()) + codeBlockOf(null, listOf("x"))
+ val again = stateOf(RichTextState(initialRichParagraphList = paragraphs).toMarkdown())
+ assertEquals(listOf("a", "", "", "x"), again.richParagraphList.map { it.plainText() })
+ assertTrue(again.richParagraphList.last().type is CodeBlock)
+ }
+
@Test
fun `two blocks in a row stay two blocks`() {
val state = stateOf("```kotlin\na\n```\n```python\nb\n```")
From 2c043f241b2bfb8dc5cfe6414f9aae7d380b1fb8 Mon Sep 17 00:00:00 2001
From: MohamedRejeb /
.
val listStyleKeywords = mutableMapOf
being read, or null outside one. Code is collected whole and turned
+ // into code block paragraphs when the element closes.
+ var preText: StringBuilder? = null
+ var preLanguage: String? = null
val handler = KsoupHtmlHandler
.Builder()
.onText {
+ preText?.let { buffer ->
+ buffer.append(KsoupEntities.decodeHtml(it))
+ return@onText
+ }
+
// In html text inside ul/ol tags is skipped
val lastOpenedTag = openedTags.lastOrNull()?.first
if (lastOpenedTag == "ul" || lastOpenedTag == "ol") return@onText
@@ -116,6 +129,24 @@ internal object RichTextStateHtmlParser : RichTextStateParser`, where spaces are kept as they are and must not become entities. */
+ private fun escapeCodeText(text: String): String =
+ text.replace("&", "&").replace("<", "<").replace(">", ">")
+
private val SpaceRunRegex = Regex(" {2,}")
/** Numeric character references for a space: decimal, hex, and zero-padded forms. */
@@ -1067,4 +1148,6 @@ internal val htmlElementsSpanStyleDecodeMap = mapOf(
)
internal const val CodeSpanTagName = "code"
-internal const val OldCodeSpanTagName = "code-span"
\ No newline at end of file
+internal const val OldCodeSpanTagName = "code-span"
+internal const val PreTagName = "pre"
+internal const val CodeLanguageClassPrefix = "language-"
\ No newline at end of file
diff --git a/richeditor-compose/src/commonTest/kotlin/com/mohamedrejeb/richeditor/parser/html/CodeBlockHtmlTest.kt b/richeditor-compose/src/commonTest/kotlin/com/mohamedrejeb/richeditor/parser/html/CodeBlockHtmlTest.kt
new file mode 100644
index 00000000..df9d7693
--- /dev/null
+++ b/richeditor-compose/src/commonTest/kotlin/com/mohamedrejeb/richeditor/parser/html/CodeBlockHtmlTest.kt
@@ -0,0 +1,187 @@
+package com.mohamedrejeb.richeditor.parser.html
+
+import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi
+import com.mohamedrejeb.richeditor.model.RichTextState
+import com.mohamedrejeb.richeditor.paragraph.codeBlockGroups
+import com.mohamedrejeb.richeditor.paragraph.plainText
+import com.mohamedrejeb.richeditor.paragraph.type.CodeBlock
+import com.mohamedrejeb.richeditor.paragraph.type.DefaultParagraph
+import com.mohamedrejeb.richeditor.paragraph.type.UnorderedList
+import kotlin.test.Test
+import kotlin.test.assertEquals
+import kotlin.test.assertTrue
+
+@OptIn(ExperimentalRichTextApi::class)
+class CodeBlockHtmlTest {
+
+ private fun stateOf(html: String) = RichTextState().apply { setHtml(html) }
+
+ private fun RichTextState.codeLines(): Listfun a() {\n val b = 1\n}a\n b
")
+ assertEquals(listOf("a", " b"), state.codeLines())
+ assertEquals(null, (state.richParagraphList.first().type as CodeBlock).language)
+ }
+
+ @Test
+ fun `the newline after the opening tag and before the closing tag is not a line`() {
+ assertEquals(listOf("a", "b"), stateOf("
").codeLines())
+ }
+
+ @Test
+ fun `blank lines tabs and entities inside pre are kept`() {
+ val state = stateOf("\na\nb\n
")
+ assertEquals(listOf("\ta < b", "", "c && d"), state.codeLines())
+ }
+
+ @Test
+ fun `markup inside pre is read as plain code`() {
+ val state = stateOf("\ta < b\n\nc && d
")
+ assertEquals(listOf("val a", "b"), state.codeLines())
+ }
+
+ @Test
+ fun `two pre elements stay two blocks`() {
+ val state = stateOf("val a
ba
")
+ assertEquals(2, state.richParagraphList.toList().codeBlockGroups().size)
+ }
+
+ @Test
+ fun `export writes pre and code with the language`() {
+ val html = "bfun a() {\n val b = 1 < 2\n}
", stateOf("a\n\nba\n\nb
").toHtml())
+ }
+
+ @Test
+ fun `a language with a quote is escaped in the class`() {
+ val state = RichTextState().apply { setMarkdown("```a\"b\nx\n```") }
+ val html = state.toHtml()
+ assertTrue("a\"b" !in html.substringBefore(">x"), "the raw quote must not appear in the tag: $html")
+ assertEquals(listOf("x"), stateOf(html).codeLines())
+ }
+
+ @Test
+ fun `code inline outside pre is still a code span`() {
+ val state = stateOf("bb
")
+ assertEquals(listOf("a"), state.lines())
+ assertEquals("a
", state.toHtml())
+ }
+
+ @Test
+ fun `an empty pre is one empty code line`() {
+ val state = stateOf("a
")
+ assertEquals(listOf(""), state.codeLines())
+ assertEquals("
", state.toHtml())
+ }
+
+ @Test
+ fun `crlf inside pre splits lines`() {
+ assertEquals(listOf("a", "b"), stateOf("a\r\nb
").codeLines())
+ }
+
+ @Test
+ fun `space runs inside pre are exported raw`() {
+ val html = "
"
+ assertEquals(html, stateOf(html).toHtml())
+ }
+
+ @Test
+ fun `text after a pre starts its own paragraph`() {
+ val state = stateOf("a b\n\tc a
b")
+ assertEquals(listOf("a", "b"), state.lines())
+ assertTrue(state.richParagraphList.last().type is DefaultParagraph)
+ }
+
+ @Test
+ fun `an unclosed pre is closed at the end`() {
+ assertEquals(listOf("a", "b"), stateOf("a\nb").codeLines())
+ }
+
+ @Test
+ fun `pre inside a p ends the paragraph and the rest follows the block`() {
+ val state = stateOf("a
After
a
b").lines()) + assertEquals(listOf("a", "b", "c"), stateOf("
a
b
c").lines()) + } + + @Test + fun `an explicit empty paragraph before a pre is kept`() { + val state = stateOf("
a") + assertEquals(listOf("", "a"), state.lines()) + assertTrue(state.richParagraphList.first().type is DefaultParagraph) + } + + @Test + fun `pre between two lists round trips`() { + val html = "
aa
a
") + assertEquals(listOf("a", "b"), state.lines()) + } + + @Test + fun `an ide clipboard pre with coloured spans and br becomes plain code lines`() { + val html = "a\nb
" + + "println(\"a b)" + + "
val c = 1
println(\"insertHtml: \$position\")
println(\"selection html: \$html\")
println(\"selection text: \$text\")
val htmlSelection = object : StringSelection(html), Transferable {
val html = \"hello\"
val richTextState = RichTextStateHtmlParser.encode(html)
Before
val a\n\n val b" +
+ "cAfter
" + val state = RichTextState().apply { setHtml(html) } + + val json = state.toJson() + val reloaded = RichTextState().setJson(json) + + assertEquals(html, reloaded.toHtml()) + assertEquals(json, reloaded.toJson()) + } +} diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/document/RichTextBlockType.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/document/RichTextBlockType.kt index bf6eaa7e..b572ab39 100644 --- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/document/RichTextBlockType.kt +++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/document/RichTextBlockType.kt @@ -25,4 +25,14 @@ public sealed interface RichTextBlockType { require(startNumber == null || ordered) { "startNumber requires an ordered list" } } } + + /** + * One line of a code block. Consecutive code lines form one block; [isBlockStart] marks its + * first line, so two blocks next to each other stay apart. [language] is the tag as written + * (`kotlin`, `js`, ...), or null when the block names none. + */ + public data class CodeBlock( + public val language: String? = null, + public val isBlockStart: Boolean = true, + ) : RichTextBlockType } diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/document/RichTextDocumentDecoder.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/document/RichTextDocumentDecoder.kt index b49036ba..c9979131 100644 --- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/document/RichTextDocumentDecoder.kt +++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/document/RichTextDocumentDecoder.kt @@ -16,6 +16,7 @@ import com.mohamedrejeb.richeditor.model.HeadingStyle import com.mohamedrejeb.richeditor.model.RichSpan import com.mohamedrejeb.richeditor.model.RichSpanStyle import com.mohamedrejeb.richeditor.paragraph.RichParagraph +import com.mohamedrejeb.richeditor.paragraph.type.CodeBlock import com.mohamedrejeb.richeditor.paragraph.type.ListStyleTypeKeywords import com.mohamedrejeb.richeditor.paragraph.type.OrderedList import com.mohamedrejeb.richeditor.paragraph.type.UnorderedList @@ -59,6 +60,9 @@ internal object RichTextDocumentDecoder { ) } } + if (type is RichTextBlockType.CodeBlock) { + paragraph.type = CodeBlock(language = type.language, isBlockStart = type.isBlockStart) + } val cuts = buildSet { add(0) diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/document/RichTextDocumentEncoder.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/document/RichTextDocumentEncoder.kt index d3d332ab..daf1e446 100644 --- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/document/RichTextDocumentEncoder.kt +++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/document/RichTextDocumentEncoder.kt @@ -15,6 +15,7 @@ import com.mohamedrejeb.richeditor.model.RichSpan import com.mohamedrejeb.richeditor.model.RichSpanStyle import com.mohamedrejeb.richeditor.model.RichTextState import com.mohamedrejeb.richeditor.paragraph.RichParagraph +import com.mohamedrejeb.richeditor.paragraph.type.CodeBlock import com.mohamedrejeb.richeditor.paragraph.type.ListStyleTypeKeywords import com.mohamedrejeb.richeditor.paragraph.type.OrderedList import com.mohamedrejeb.richeditor.paragraph.type.UnorderedList @@ -75,6 +76,10 @@ internal object RichTextDocumentEncoder { listStyleType = ListStyleTypeKeywords.keywordOf(paragraphType), ) } + is CodeBlock -> { + orderedCounters.clear() + RichTextBlockType.CodeBlock(language = paragraphType.language, isBlockStart = paragraphType.isBlockStart) + } else -> { orderedCounters.clear() RichTextBlockType.Paragraph diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/model/RichTextFeature.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/model/RichTextFeature.kt index ebc15d77..bf3501d7 100644 --- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/model/RichTextFeature.kt +++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/model/RichTextFeature.kt @@ -68,6 +68,9 @@ public enum class RichTextFeature { /** Heading levels 1 to 6. */ Heading, + /** Multi-line code blocks. */ + CodeBlock, + /** Paragraph alignment, direction, first-line indent and line height. */ ParagraphStyle; diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/model/RichTextFeatureFilter.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/model/RichTextFeatureFilter.kt index 32307c95..38b1f653 100644 --- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/model/RichTextFeatureFilter.kt +++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/model/RichTextFeatureFilter.kt @@ -38,8 +38,11 @@ private fun RichTextBlock.restrictedTo(features: Set` is imported as a code block: its lines are drawn
+in a fixed-width font on a background, and coloured by the language the block names (keywords,
+strings, numbers, comments, annotations). `RichText` and the editors both draw it. The colours
+are presentation only, they are never written to HTML, Markdown or JSON.
-Stay tuned for updates!
+Code blocks are experimental API (`@ExperimentalRichTextApi`).
+
+### Basic usage
+
+```kotlin
+val state = rememberRichTextState()
+
+LaunchedEffect(Unit) {
+ state.setMarkdown(
+ """
+ Here is a function:
+
+ ```kotlin
+ fun greet() = println("Hi")
+ ```
+ """.trimIndent()
+ )
+}
+
+RichText(state = state, modifier = Modifier.fillMaxWidth())
+```
+
+The background is as wide as the composable, so give it the width the block should have
+(`fillMaxWidth()` in most layouts).
+
+The same block in each format:
+
+| Format | Form |
+|---|---|
+| Markdown | A fence of three or more backticks with the language after it. Export uses a fence longer than any backtick run in the code |
+| HTML | `...
`. A `` without `` or without a class is a block with no language |
+| JSON | One `"type": "code-block"` block per line, with `"language"` and `"start": true` on the first line of a block |
+
+The text inside a block is kept exactly as written: indentation, tabs, blank lines, and Markdown
+or HTML that would otherwise be formatting.
+
+### Customizing
+
+| Property on `RichTextState.config` | Type | Default | Description |
+|---|---|---|---|
+| `codeBlockBackgroundColor` | `Color` | translucent grey | The background drawn behind a block |
+| `codeBlockFontFamily` | `FontFamily` | `FontFamily.Monospace` | The font of the code |
+| `codeBlockColors` | `CodeBlockColors` | `CodeBlockColors.Default` | The style of each kind of token |
+
+`CodeBlockColors` holds a `SpanStyle` per token kind, not just a colour, so a comment can be
+italic:
+
+```kotlin
+val scheme = MaterialTheme.colorScheme
+
+state.config.codeBlockBackgroundColor = scheme.surfaceVariant
+state.config.codeBlockColors = CodeBlockColors(
+ keyword = SpanStyle(color = scheme.primary),
+ string = SpanStyle(color = scheme.tertiary),
+ number = SpanStyle(color = scheme.secondary),
+ comment = SpanStyle(color = scheme.outline, fontStyle = FontStyle.Italic),
+ annotation = SpanStyle(color = scheme.secondary),
+)
+```
+
+`CodeBlockColors.Default` uses mid-tone colours that stay readable on light and dark backgrounds.
+
+### Turning code blocks off
+
+Code blocks are one of the [editor features](features.md). An editor whose feature set leaves out
+`RichTextFeature.CodeBlock` loads and pastes a code block as plain paragraphs:
+
+```kotlin
+state.config.features = RichTextFeature.All - RichTextFeature.CodeBlock
+```
+
+## Showing Code Alone
+
+To show code that is not part of a rich text, such as a snippet or a whole file, use
+`BasicCodeText`. It needs no `RichTextState`:
+
+```kotlin
+BasicCodeText(
+ code = "fun greet() = println(\"Hi\")",
+ language = CodeLanguage.Kotlin,
+ modifier = Modifier
+ .fillMaxWidth()
+ .background(MaterialTheme.colorScheme.surfaceVariant, RoundedCornerShape(8.dp))
+ .padding(12.dp),
+)
+```
+
+| Parameter | Type | Default | Description |
+|---|---|---|---|
+| `code` | `String` | required | The code to show |
+| `language` | `CodeLanguage?` | required | The language to colour by, or null to draw the code plain |
+| `modifier` | `Modifier` | `Modifier` | Background, padding and shape come from here |
+| `style` | `TextStyle` | monospace | The text style of the code |
+| `colors` | `CodeBlockColors` | `CodeBlockColors.Default` | The style of each kind of token |
+| `softWrap` | `Boolean` | `false` | When false, a long line scrolls sideways instead of wrapping |
+| `onTextLayout` | `(TextLayoutResult) -> Unit` | `{}` | Called when the text is laid out |
+
+`BasicCodeText` draws the text and nothing else, so it fits any design system.
+
+For a `Text` of your own, `highlightCode` returns the coloured `AnnotatedString`:
+
+```kotlin
+Text(text = highlightCode(code, CodeLanguage.fromName("python")))
+```
+
+## Custom Layouts Such as a Diff View
+
+A view that draws its own rows, for example a diff with a gutter and added or removed
+backgrounds, needs the tokens of each line. `CodeHighlighter.tokenizeLines` returns them with
+offsets relative to each line. The lines are read as one piece of code, so a comment or string
+that opens on one line is still coloured on the next:
+
+```kotlin
+val language = CodeLanguage.fromFileName("src/main/kotlin/Greeter.kt") ?: return
+val colors = CodeBlockColors.Default
+val tokens = CodeHighlighter.tokenizeLines(lines, language)
+
+lines.forEachIndexed { index, line ->
+ val text = buildAnnotatedString {
+ append(line)
+ tokens[index].forEach { token ->
+ addStyle(colors.styleOf(token.kind), token.start, token.end)
+ }
+ }
+ DiffRow(text)
+}
+```
+
+Lines that do not follow each other in the file, such as two hunks of a diff, are two calls.
+A hunk that starts in the middle of a comment or string is coloured as code until that comment
+or string ends, because the lines above it are not known.
+
+`CodeHighlighter.tokenize(code, language)` returns the tokens of a whole piece of code.
+Tokenizing is linear in the length of the code and never throws, whatever the input.
+
+## Supported Languages
+
+| Language | `CodeLanguage` | Names it answers to | File endings |
+|---|---|---|---|
+| Kotlin | `Kotlin` | `kotlin`, `kt`, `kts` | `kt`, `kts` |
+| Java | `Java` | `java` | `java` |
+| JavaScript | `JavaScript` | `javascript`, `js`, `jsx`, `mjs`, `cjs`, `node` | `js`, `jsx`, `mjs`, `cjs` |
+| TypeScript | `TypeScript` | `typescript`, `ts`, `tsx` | `ts`, `tsx` |
+| Python | `Python` | `python`, `py`, `python3` | `py` |
+| Swift | `Swift` | `swift` | `swift` |
+| Go | `Go` | `go`, `golang` | `go` |
+| Rust | `Rust` | `rust`, `rs` | `rs` |
+| C | `C` | `c`, `h` | `c`, `h` |
+| C++ | `Cpp` | `cpp`, `c++`, `cc`, `cxx`, `hpp` | `cpp`, `cc`, `cxx`, `hpp`, `hh` |
+| C# | `CSharp` | `csharp`, `cs`, `c#` | `cs` |
+| Dart | `Dart` | `dart` | `dart` |
+| Shell | `Shell` | `shell`, `sh`, `bash`, `zsh`, `shellscript` | `sh`, `bash`, `zsh` |
+| SQL | `Sql` | `sql` | `sql` |
+| JSON | `Json` | `json` | `json` |
+| YAML | `Yaml` | `yaml`, `yml` | `yaml`, `yml` |
+
+`CodeLanguage.fromName` takes the name of a fence or of a `language-x` class, ignoring case, and
+`CodeLanguage.fromFileName` takes a file name or path. Both return null for a language the
+library does not know. A code block with an unknown language is drawn as plain code and keeps
+its language tag on export.
+
+## Limitations
+
+- A long line in a code block inside `RichText` or an editor wraps. Use `BasicCodeText` when the
+ code should scroll sideways.
+- There is no editor action yet to turn text into a code block or to leave one. A code block
+ that was loaded can be edited, and Enter adds a line to it.
+- Only fenced Markdown code is a code block. Code indented by four spaces is not.
+- HTML, XML, CSS and diffs are not coloured yet.
+- Markup inside an HTML `` is read as plain code, so the colours of code copied from an IDE
+ are replaced by the block's own.
+- A code block inside a list item or a quote is moved to the top level.
+- `ExpandableBasicRichText` colours the code but draws no background behind it.
+
+## Related
+
+- For the feature set that switches code blocks on and off, see [Editor features](features.md).
+- For format details, see [HTML Import and Export](html_import_export.md),
+ [Markdown Import and Export](markdown_import_export.md) and
+ [JSON Import and Export](json_import_export.md).
+- For the block model behind the JSON format, see [Rich Text Document](rich_text_document.md).
diff --git a/docs/html_import_export.md b/docs/html_import_export.md
index a3e33227..4a4c04c5 100644
--- a/docs/html_import_export.md
+++ b/docs/html_import_export.md
@@ -60,6 +60,7 @@ The following HTML tags are supported:
- `` - Paragraphs
- `
` - Divisions
- `
` - Line breaks
+- `` - Code blocks, with the language from `` (see [Code Blocks](code_blocks.md))
- ``..`` - Headings (see [Headings](headings.md))
- `` - Unordered lists. `style="list-style-type: ..."` sets the bullet (`disc`, `circle`, `square`)
- `` - Ordered lists. `start="N"` sets the first item's number; `style="list-style-type: ..."` sets the numbering (`decimal`, `lower-alpha`, `upper-alpha`, `lower-roman`, `upper-roman`, `arabic-indic`, `arabic-abjad`)
diff --git a/docs/json_import_export.md b/docs/json_import_export.md
index 9004a484..4477caca 100644
--- a/docs/json_import_export.md
+++ b/docs/json_import_export.md
@@ -55,10 +55,11 @@ Block fields:
| Field | When present | Meaning |
|---|---|---|
| `id` | always | `"b" + index`; accepted and ignored on import |
-| `type` | always | `paragraph`, `heading`, or `list-item` |
+| `type` | always | `paragraph`, `heading`, `list-item`, or `code-block` |
| `level` | headings | Heading level 1 to 6 |
| `ordered`, `indent`, `start` | list items | Ordered flag, 0-based nesting, numbering restart |
| `listStyle` | list items with a style of their own | CSS `list-style-type` keyword of the item's list (`lower-alpha`, `square`, ...) |
+| `language`, `start` | code blocks | One block per line of code: the language tag as written, and `true` on the first line of a block (see [Code Blocks](code_blocks.md)). A library version from before code blocks rejects a document that contains one |
| `align`, `dir`, `lineHeight`, `textIndent` | when set | Paragraph style |
| `br` | line-break paragraphs | Paragraph created by `
` |
| `text`, `spans` | always | Content and styling marks |
diff --git a/docs/markdown_import_export.md b/docs/markdown_import_export.md
index dc4fe64b..c8f36321 100644
--- a/docs/markdown_import_export.md
+++ b/docs/markdown_import_export.md
@@ -55,6 +55,7 @@ The following Markdown syntax elements are supported:
- `*text*` or `_text_` - Italic text
- `~~text~~` - Strikethrough text
- `` `code` `` - Code spans
+- Fenced code with a language after the opening fence - Code blocks (see [Code Blocks](code_blocks.md))
### Headings
- `# Title` through `###### Title` - ATX headings H1..H6 (see [Headings](headings.md))
diff --git a/docs/rich_text_document.md b/docs/rich_text_document.md
index 8693517f..4ccb5c8f 100644
--- a/docs/rich_text_document.md
+++ b/docs/rich_text_document.md
@@ -29,7 +29,7 @@ A document is a list of blocks, one per paragraph:
| `RichTextBlock` field | Type | Meaning |
|---|---|---|
| `text` | `String` | Flattened paragraph text. List prefixes are excluded. Each inline image occupies one U+FFFC placeholder character. |
-| `type` | `RichTextBlockType` | `Paragraph` or `ListItem(ordered, indent, startNumber, listStyleType)` |
+| `type` | `RichTextBlockType` | `Paragraph`, `ListItem(ordered, indent, startNumber, listStyleType)` or `CodeBlock(language, isBlockStart)`, one per line of code |
| `spans` | `List` | Styling marks over inclusive character ranges of `text` |
| `headingLevel` | `Int` | 0 for normal text, 1 to 6 for headings |
| `textAlign` | `TextAlign` | Paragraph alignment, `Unspecified` when not set |
diff --git a/richeditor-compose/api/desktop/richeditor-compose.api b/richeditor-compose/api/desktop/richeditor-compose.api
index 24bd2da4..424adbc5 100644
--- a/richeditor-compose/api/desktop/richeditor-compose.api
+++ b/richeditor-compose/api/desktop/richeditor-compose.api
@@ -36,6 +36,22 @@ public final class com/mohamedrejeb/richeditor/document/RichTextBlock {
public abstract interface class com/mohamedrejeb/richeditor/document/RichTextBlockType {
}
+public final class com/mohamedrejeb/richeditor/document/RichTextBlockType$CodeBlock : com/mohamedrejeb/richeditor/document/RichTextBlockType {
+ public static final field $stable I
+ public fun ()V
+ public fun (Ljava/lang/String;Z)V
+ public synthetic fun (Ljava/lang/String;ZILkotlin/jvm/internal/DefaultConstructorMarker;)V
+ public final fun component1 ()Ljava/lang/String;
+ public final fun component2 ()Z
+ public final fun copy (Ljava/lang/String;Z)Lcom/mohamedrejeb/richeditor/document/RichTextBlockType$CodeBlock;
+ public static synthetic fun copy$default (Lcom/mohamedrejeb/richeditor/document/RichTextBlockType$CodeBlock;Ljava/lang/String;ZILjava/lang/Object;)Lcom/mohamedrejeb/richeditor/document/RichTextBlockType$CodeBlock;
+ public fun equals (Ljava/lang/Object;)Z
+ public final fun getLanguage ()Ljava/lang/String;
+ public fun hashCode ()I
+ public final fun isBlockStart ()Z
+ public fun toString ()Ljava/lang/String;
+}
+
public final class com/mohamedrejeb/richeditor/document/RichTextBlockType$ListItem : com/mohamedrejeb/richeditor/document/RichTextBlockType {
public static final field $stable I
public fun (ZILjava/lang/Integer;Ljava/lang/String;)V
@@ -331,6 +347,87 @@ public final class com/mohamedrejeb/richeditor/document/RichTextSpanMark$Unknown
public fun toString ()Ljava/lang/String;
}
+public final class com/mohamedrejeb/richeditor/highlight/CodeBlockColors {
+ public static final field $stable I
+ public static final field Companion Lcom/mohamedrejeb/richeditor/highlight/CodeBlockColors$Companion;
+ public fun (Landroidx/compose/ui/text/SpanStyle;Landroidx/compose/ui/text/SpanStyle;Landroidx/compose/ui/text/SpanStyle;Landroidx/compose/ui/text/SpanStyle;Landroidx/compose/ui/text/SpanStyle;)V
+ public fun equals (Ljava/lang/Object;)Z
+ public final fun getAnnotation ()Landroidx/compose/ui/text/SpanStyle;
+ public final fun getComment ()Landroidx/compose/ui/text/SpanStyle;
+ public final fun getKeyword ()Landroidx/compose/ui/text/SpanStyle;
+ public final fun getNumber ()Landroidx/compose/ui/text/SpanStyle;
+ public final fun getString ()Landroidx/compose/ui/text/SpanStyle;
+ public fun hashCode ()I
+ public final fun styleOf (Lcom/mohamedrejeb/richeditor/highlight/CodeTokenKind;)Landroidx/compose/ui/text/SpanStyle;
+}
+
+public final class com/mohamedrejeb/richeditor/highlight/CodeBlockColors$Companion {
+ public final fun getDefault ()Lcom/mohamedrejeb/richeditor/highlight/CodeBlockColors;
+}
+
+public final class com/mohamedrejeb/richeditor/highlight/CodeHighlighter {
+ public static final field $stable I
+ public static final field INSTANCE Lcom/mohamedrejeb/richeditor/highlight/CodeHighlighter;
+ public final fun tokenize (Ljava/lang/String;Lcom/mohamedrejeb/richeditor/highlight/CodeLanguage;)Ljava/util/List;
+ public final fun tokenizeLines (Ljava/util/List;Lcom/mohamedrejeb/richeditor/highlight/CodeLanguage;)Ljava/util/List;
+}
+
+public final class com/mohamedrejeb/richeditor/highlight/CodeLanguage {
+ public static final field $stable I
+ public static final field Companion Lcom/mohamedrejeb/richeditor/highlight/CodeLanguage$Companion;
+ public final fun getName ()Ljava/lang/String;
+ public fun toString ()Ljava/lang/String;
+}
+
+public final class com/mohamedrejeb/richeditor/highlight/CodeLanguage$Companion {
+ public final fun fromFileName (Ljava/lang/String;)Lcom/mohamedrejeb/richeditor/highlight/CodeLanguage;
+ public final fun fromName (Ljava/lang/String;)Lcom/mohamedrejeb/richeditor/highlight/CodeLanguage;
+ public final fun getAll ()Ljava/util/List;
+ public final fun getC ()Lcom/mohamedrejeb/richeditor/highlight/CodeLanguage;
+ public final fun getCSharp ()Lcom/mohamedrejeb/richeditor/highlight/CodeLanguage;
+ public final fun getCpp ()Lcom/mohamedrejeb/richeditor/highlight/CodeLanguage;
+ public final fun getDart ()Lcom/mohamedrejeb/richeditor/highlight/CodeLanguage;
+ public final fun getGo ()Lcom/mohamedrejeb/richeditor/highlight/CodeLanguage;
+ public final fun getJava ()Lcom/mohamedrejeb/richeditor/highlight/CodeLanguage;
+ public final fun getJavaScript ()Lcom/mohamedrejeb/richeditor/highlight/CodeLanguage;
+ public final fun getJson ()Lcom/mohamedrejeb/richeditor/highlight/CodeLanguage;
+ public final fun getKotlin ()Lcom/mohamedrejeb/richeditor/highlight/CodeLanguage;
+ public final fun getPython ()Lcom/mohamedrejeb/richeditor/highlight/CodeLanguage;
+ public final fun getRust ()Lcom/mohamedrejeb/richeditor/highlight/CodeLanguage;
+ public final fun getShell ()Lcom/mohamedrejeb/richeditor/highlight/CodeLanguage;
+ public final fun getSql ()Lcom/mohamedrejeb/richeditor/highlight/CodeLanguage;
+ public final fun getSwift ()Lcom/mohamedrejeb/richeditor/highlight/CodeLanguage;
+ public final fun getTypeScript ()Lcom/mohamedrejeb/richeditor/highlight/CodeLanguage;
+ public final fun getYaml ()Lcom/mohamedrejeb/richeditor/highlight/CodeLanguage;
+}
+
+public final class com/mohamedrejeb/richeditor/highlight/CodeToken {
+ public static final field $stable I
+ public fun (IILcom/mohamedrejeb/richeditor/highlight/CodeTokenKind;)V
+ public fun equals (Ljava/lang/Object;)Z
+ public final fun getEnd ()I
+ public final fun getKind ()Lcom/mohamedrejeb/richeditor/highlight/CodeTokenKind;
+ public final fun getStart ()I
+ public fun hashCode ()I
+ public fun toString ()Ljava/lang/String;
+}
+
+public final class com/mohamedrejeb/richeditor/highlight/CodeTokenKind : java/lang/Enum {
+ public static final field Annotation Lcom/mohamedrejeb/richeditor/highlight/CodeTokenKind;
+ public static final field Comment Lcom/mohamedrejeb/richeditor/highlight/CodeTokenKind;
+ public static final field Keyword Lcom/mohamedrejeb/richeditor/highlight/CodeTokenKind;
+ public static final field Number Lcom/mohamedrejeb/richeditor/highlight/CodeTokenKind;
+ public static final field String Lcom/mohamedrejeb/richeditor/highlight/CodeTokenKind;
+ public static fun getEntries ()Lkotlin/enums/EnumEntries;
+ public static fun valueOf (Ljava/lang/String;)Lcom/mohamedrejeb/richeditor/highlight/CodeTokenKind;
+ public static fun values ()[Lcom/mohamedrejeb/richeditor/highlight/CodeTokenKind;
+}
+
+public final class com/mohamedrejeb/richeditor/highlight/HighlightCodeKt {
+ public static final fun highlightCode (Ljava/lang/String;Lcom/mohamedrejeb/richeditor/highlight/CodeLanguage;Lcom/mohamedrejeb/richeditor/highlight/CodeBlockColors;)Landroidx/compose/ui/text/AnnotatedString;
+ public static synthetic fun highlightCode$default (Ljava/lang/String;Lcom/mohamedrejeb/richeditor/highlight/CodeLanguage;Lcom/mohamedrejeb/richeditor/highlight/CodeBlockColors;ILjava/lang/Object;)Landroidx/compose/ui/text/AnnotatedString;
+}
+
public final class com/mohamedrejeb/richeditor/model/DefaultImageLoader : com/mohamedrejeb/richeditor/model/ImageLoader {
public static final field $stable I
public static final field INSTANCE Lcom/mohamedrejeb/richeditor/model/DefaultImageLoader;
@@ -493,6 +590,9 @@ public final class com/mohamedrejeb/richeditor/model/RichSpanStyleRegistry$Compa
public final class com/mohamedrejeb/richeditor/model/RichTextConfig {
public static final field $stable I
public final fun getAutoLinkEnabled ()Z
+ public final fun getCodeBlockBackgroundColor-0d7_KjU ()J
+ public final fun getCodeBlockColors ()Lcom/mohamedrejeb/richeditor/highlight/CodeBlockColors;
+ public final fun getCodeBlockFontFamily ()Landroidx/compose/ui/text/font/FontFamily;
public final fun getCodeSpanBackgroundColor-0d7_KjU ()J
public final fun getCodeSpanColor-0d7_KjU ()J
public final fun getCodeSpanCornerRadius-XSAIIZE ()J
@@ -518,6 +618,9 @@ public final class com/mohamedrejeb/richeditor/model/RichTextConfig {
public final fun getUnorderedListIndent ()I
public final fun getUnorderedListStyleType ()Lcom/mohamedrejeb/richeditor/paragraph/type/UnorderedListStyleType;
public final fun setAutoLinkEnabled (Z)V
+ public final fun setCodeBlockBackgroundColor-8_81llA (J)V
+ public final fun setCodeBlockColors (Lcom/mohamedrejeb/richeditor/highlight/CodeBlockColors;)V
+ public final fun setCodeBlockFontFamily (Landroidx/compose/ui/text/font/FontFamily;)V
public final fun setCodeSpanBackgroundColor-8_81llA (J)V
public final fun setCodeSpanColor-8_81llA (J)V
public final fun setCodeSpanCornerRadius--R2X_6o (J)V
@@ -547,6 +650,7 @@ public final class com/mohamedrejeb/richeditor/model/RichTextConfig {
public final class com/mohamedrejeb/richeditor/model/RichTextFeature : java/lang/Enum {
public static final field BaselineShift Lcom/mohamedrejeb/richeditor/model/RichTextFeature;
public static final field Bold Lcom/mohamedrejeb/richeditor/model/RichTextFeature;
+ public static final field CodeBlock Lcom/mohamedrejeb/richeditor/model/RichTextFeature;
public static final field CodeSpan Lcom/mohamedrejeb/richeditor/model/RichTextFeature;
public static final field Companion Lcom/mohamedrejeb/richeditor/model/RichTextFeature$Companion;
public static final field CustomSpanStyle Lcom/mohamedrejeb/richeditor/model/RichTextFeature;
@@ -906,6 +1010,10 @@ public final class com/mohamedrejeb/richeditor/paragraph/type/UnorderedListStyle
public final fun getSquare ()Lcom/mohamedrejeb/richeditor/paragraph/type/UnorderedListStyleType;
}
+public final class com/mohamedrejeb/richeditor/ui/BasicCodeTextKt {
+ public static final fun BasicCodeText (Ljava/lang/String;Lcom/mohamedrejeb/richeditor/highlight/CodeLanguage;Landroidx/compose/ui/Modifier;Landroidx/compose/ui/text/TextStyle;Lcom/mohamedrejeb/richeditor/highlight/CodeBlockColors;ZLkotlin/jvm/functions/Function1;Landroidx/compose/runtime/Composer;II)V
+}
+
public final class com/mohamedrejeb/richeditor/ui/BasicRichTextEditorKt {
public static final fun BasicRichTextEditor (Lcom/mohamedrejeb/richeditor/model/RichTextState;Landroidx/compose/ui/Modifier;ZZLandroidx/compose/ui/text/TextStyle;Landroidx/compose/foundation/text/KeyboardOptions;Landroidx/compose/foundation/text/KeyboardActions;ZIIILkotlin/jvm/functions/Function1;Landroidx/compose/foundation/interaction/MutableInteractionSource;Landroidx/compose/ui/graphics/Brush;Lcom/mohamedrejeb/richeditor/ui/UndoBehavior;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;III)V
public static final fun BasicRichTextEditor (Lcom/mohamedrejeb/richeditor/model/RichTextState;Landroidx/compose/ui/Modifier;ZZLandroidx/compose/ui/text/TextStyle;Landroidx/compose/foundation/text/KeyboardOptions;Landroidx/compose/foundation/text/KeyboardActions;ZZIIILkotlin/jvm/functions/Function1;Landroidx/compose/foundation/interaction/MutableInteractionSource;Landroidx/compose/ui/graphics/Brush;Lcom/mohamedrejeb/richeditor/ui/UndoBehavior;Lkotlin/jvm/functions/Function3;Landroidx/compose/foundation/layout/PaddingValues;Landroidx/compose/runtime/Composer;III)V
diff --git a/richeditor-compose/api/richeditor-compose.klib.api b/richeditor-compose/api/richeditor-compose.klib.api
index e849e432..db20d4a3 100644
--- a/richeditor-compose/api/richeditor-compose.klib.api
+++ b/richeditor-compose/api/richeditor-compose.klib.api
@@ -14,6 +14,20 @@ open annotation class com.mohamedrejeb.richeditor.annotation/InternalRichTextApi
constructor () // com.mohamedrejeb.richeditor.annotation/InternalRichTextApi.|(){}[0]
}
+final enum class com.mohamedrejeb.richeditor.highlight/CodeTokenKind : kotlin/Enum { // com.mohamedrejeb.richeditor.highlight/CodeTokenKind|null[0]
+ enum entry Annotation // com.mohamedrejeb.richeditor.highlight/CodeTokenKind.Annotation|null[0]
+ enum entry Comment // com.mohamedrejeb.richeditor.highlight/CodeTokenKind.Comment|null[0]
+ enum entry Keyword // com.mohamedrejeb.richeditor.highlight/CodeTokenKind.Keyword|null[0]
+ enum entry Number // com.mohamedrejeb.richeditor.highlight/CodeTokenKind.Number|null[0]
+ enum entry String // com.mohamedrejeb.richeditor.highlight/CodeTokenKind.String|null[0]
+
+ final val entries // com.mohamedrejeb.richeditor.highlight/CodeTokenKind.entries|#static{}entries[0]
+ final fun (): kotlin.enums/EnumEntries // com.mohamedrejeb.richeditor.highlight/CodeTokenKind.entries.|#static(){}[0]
+
+ final fun valueOf(kotlin/String): com.mohamedrejeb.richeditor.highlight/CodeTokenKind // com.mohamedrejeb.richeditor.highlight/CodeTokenKind.valueOf|valueOf#static(kotlin.String){}[0]
+ final fun values(): kotlin/Array // com.mohamedrejeb.richeditor.highlight/CodeTokenKind.values|values#static(){}[0]
+}
+
final enum class com.mohamedrejeb.richeditor.model/HeadingStyle : kotlin/Enum { // com.mohamedrejeb.richeditor.model/HeadingStyle|null[0]
enum entry H1 // com.mohamedrejeb.richeditor.model/HeadingStyle.H1|null[0]
enum entry H2 // com.mohamedrejeb.richeditor.model/HeadingStyle.H2|null[0]
@@ -39,6 +53,7 @@ final enum class com.mohamedrejeb.richeditor.model/HeadingStyle : kotlin/Enum { // com.mohamedrejeb.richeditor.model/RichTextFeature|null[0]
enum entry BaselineShift // com.mohamedrejeb.richeditor.model/RichTextFeature.BaselineShift|null[0]
enum entry Bold // com.mohamedrejeb.richeditor.model/RichTextFeature.Bold|null[0]
+ enum entry CodeBlock // com.mohamedrejeb.richeditor.model/RichTextFeature.CodeBlock|null[0]
enum entry CodeSpan // com.mohamedrejeb.richeditor.model/RichTextFeature.CodeSpan|null[0]
enum entry CustomSpanStyle // com.mohamedrejeb.richeditor.model/RichTextFeature.CustomSpanStyle|null[0]
enum entry FontSize // com.mohamedrejeb.richeditor.model/RichTextFeature.FontSize|null[0]
@@ -264,6 +279,22 @@ abstract interface com.mohamedrejeb.richeditor.paragraph.type/OrderedListStyleTy
}
sealed interface com.mohamedrejeb.richeditor.document/RichTextBlockType { // com.mohamedrejeb.richeditor.document/RichTextBlockType|null[0]
+ final class CodeBlock : com.mohamedrejeb.richeditor.document/RichTextBlockType { // com.mohamedrejeb.richeditor.document/RichTextBlockType.CodeBlock|null[0]
+ constructor (kotlin/String? = ..., kotlin/Boolean = ...) // com.mohamedrejeb.richeditor.document/RichTextBlockType.CodeBlock.|(kotlin.String?;kotlin.Boolean){}[0]
+
+ final val isBlockStart // com.mohamedrejeb.richeditor.document/RichTextBlockType.CodeBlock.isBlockStart|{}isBlockStart[0]
+ final fun (): kotlin/Boolean // com.mohamedrejeb.richeditor.document/RichTextBlockType.CodeBlock.isBlockStart.|(){}[0]
+ final val language // com.mohamedrejeb.richeditor.document/RichTextBlockType.CodeBlock.language|{}language[0]
+ final fun (): kotlin/String? // com.mohamedrejeb.richeditor.document/RichTextBlockType.CodeBlock.language.|(){}[0]
+
+ final fun component1(): kotlin/String? // com.mohamedrejeb.richeditor.document/RichTextBlockType.CodeBlock.component1|component1(){}[0]
+ final fun component2(): kotlin/Boolean // com.mohamedrejeb.richeditor.document/RichTextBlockType.CodeBlock.component2|component2(){}[0]
+ final fun copy(kotlin/String? = ..., kotlin/Boolean = ...): com.mohamedrejeb.richeditor.document/RichTextBlockType.CodeBlock // com.mohamedrejeb.richeditor.document/RichTextBlockType.CodeBlock.copy|copy(kotlin.String?;kotlin.Boolean){}[0]
+ final fun equals(kotlin/Any?): kotlin/Boolean // com.mohamedrejeb.richeditor.document/RichTextBlockType.CodeBlock.equals|equals(kotlin.Any?){}[0]
+ final fun hashCode(): kotlin/Int // com.mohamedrejeb.richeditor.document/RichTextBlockType.CodeBlock.hashCode|hashCode(){}[0]
+ final fun toString(): kotlin/String // com.mohamedrejeb.richeditor.document/RichTextBlockType.CodeBlock.toString|toString(){}[0]
+ }
+
final class ListItem : com.mohamedrejeb.richeditor.document/RichTextBlockType { // com.mohamedrejeb.richeditor.document/RichTextBlockType.ListItem|null[0]
constructor (kotlin/Boolean, kotlin/Int = ..., kotlin/Int? = ..., kotlin/String? = ...) // com.mohamedrejeb.richeditor.document/RichTextBlockType.ListItem.|(kotlin.Boolean;kotlin.Int;kotlin.Int?;kotlin.String?){}[0]
@@ -636,6 +667,92 @@ final class com.mohamedrejeb.richeditor.document/RichTextDocument { // com.moham
}
}
+final class com.mohamedrejeb.richeditor.highlight/CodeBlockColors { // com.mohamedrejeb.richeditor.highlight/CodeBlockColors|null[0]
+ constructor (androidx.compose.ui.text/SpanStyle, androidx.compose.ui.text/SpanStyle, androidx.compose.ui.text/SpanStyle, androidx.compose.ui.text/SpanStyle, androidx.compose.ui.text/SpanStyle) // com.mohamedrejeb.richeditor.highlight/CodeBlockColors.|(androidx.compose.ui.text.SpanStyle;androidx.compose.ui.text.SpanStyle;androidx.compose.ui.text.SpanStyle;androidx.compose.ui.text.SpanStyle;androidx.compose.ui.text.SpanStyle){}[0]
+
+ final val annotation // com.mohamedrejeb.richeditor.highlight/CodeBlockColors.annotation|{}annotation[0]
+ final fun (): androidx.compose.ui.text/SpanStyle // com.mohamedrejeb.richeditor.highlight/CodeBlockColors.annotation.|(){}[0]
+ final val comment // com.mohamedrejeb.richeditor.highlight/CodeBlockColors.comment|{}comment[0]
+ final fun (): androidx.compose.ui.text/SpanStyle // com.mohamedrejeb.richeditor.highlight/CodeBlockColors.comment.|(){}[0]
+ final val keyword // com.mohamedrejeb.richeditor.highlight/CodeBlockColors.keyword|{}keyword[0]
+ final fun (): androidx.compose.ui.text/SpanStyle // com.mohamedrejeb.richeditor.highlight/CodeBlockColors.keyword.|(){}[0]
+ final val number // com.mohamedrejeb.richeditor.highlight/CodeBlockColors.number|{}number[0]
+ final fun (): androidx.compose.ui.text/SpanStyle // com.mohamedrejeb.richeditor.highlight/CodeBlockColors.number.|(){}[0]
+ final val string // com.mohamedrejeb.richeditor.highlight/CodeBlockColors.string|{}string[0]
+ final fun (): androidx.compose.ui.text/SpanStyle // com.mohamedrejeb.richeditor.highlight/CodeBlockColors.string.|(){}[0]
+
+ final fun equals(kotlin/Any?): kotlin/Boolean // com.mohamedrejeb.richeditor.highlight/CodeBlockColors.equals|equals(kotlin.Any?){}[0]
+ final fun hashCode(): kotlin/Int // com.mohamedrejeb.richeditor.highlight/CodeBlockColors.hashCode|hashCode(){}[0]
+ final fun styleOf(com.mohamedrejeb.richeditor.highlight/CodeTokenKind): androidx.compose.ui.text/SpanStyle // com.mohamedrejeb.richeditor.highlight/CodeBlockColors.styleOf|styleOf(com.mohamedrejeb.richeditor.highlight.CodeTokenKind){}[0]
+
+ final object Companion { // com.mohamedrejeb.richeditor.highlight/CodeBlockColors.Companion|null[0]
+ final val Default // com.mohamedrejeb.richeditor.highlight/CodeBlockColors.Companion.Default|{}Default[0]
+ final fun (): com.mohamedrejeb.richeditor.highlight/CodeBlockColors // com.mohamedrejeb.richeditor.highlight/CodeBlockColors.Companion.Default.|(){}[0]
+ }
+}
+
+final class com.mohamedrejeb.richeditor.highlight/CodeLanguage { // com.mohamedrejeb.richeditor.highlight/CodeLanguage|null[0]
+ final val name // com.mohamedrejeb.richeditor.highlight/CodeLanguage.name|{}name[0]
+ final fun (): kotlin/String // com.mohamedrejeb.richeditor.highlight/CodeLanguage.name.|(){}[0]
+
+ final fun toString(): kotlin/String // com.mohamedrejeb.richeditor.highlight/CodeLanguage.toString|toString(){}[0]
+
+ final object Companion { // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion|null[0]
+ final val C // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.C|{}C[0]
+ final fun (): com.mohamedrejeb.richeditor.highlight/CodeLanguage // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.C.|(){}[0]
+ final val CSharp // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.CSharp|{}CSharp[0]
+ final fun (): com.mohamedrejeb.richeditor.highlight/CodeLanguage // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.CSharp.|(){}[0]
+ final val Cpp // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.Cpp|{}Cpp[0]
+ final fun (): com.mohamedrejeb.richeditor.highlight/CodeLanguage // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.Cpp.|(){}[0]
+ final val Dart // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.Dart|{}Dart[0]
+ final fun (): com.mohamedrejeb.richeditor.highlight/CodeLanguage // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.Dart.|(){}[0]
+ final val Go // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.Go|{}Go[0]
+ final fun (): com.mohamedrejeb.richeditor.highlight/CodeLanguage // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.Go.|(){}[0]
+ final val Java // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.Java|{}Java[0]
+ final fun (): com.mohamedrejeb.richeditor.highlight/CodeLanguage // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.Java.|(){}[0]
+ final val JavaScript // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.JavaScript|{}JavaScript[0]
+ final fun (): com.mohamedrejeb.richeditor.highlight/CodeLanguage // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.JavaScript.|(){}[0]
+ final val Json // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.Json|{}Json[0]
+ final fun (): com.mohamedrejeb.richeditor.highlight/CodeLanguage // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.Json.|(){}[0]
+ final val Kotlin // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.Kotlin|{}Kotlin[0]
+ final fun (): com.mohamedrejeb.richeditor.highlight/CodeLanguage // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.Kotlin.|(){}[0]
+ final val Python // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.Python|{}Python[0]
+ final fun (): com.mohamedrejeb.richeditor.highlight/CodeLanguage // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.Python.|(){}[0]
+ final val Rust // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.Rust|{}Rust[0]
+ final fun (): com.mohamedrejeb.richeditor.highlight/CodeLanguage // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.Rust.|(){}[0]
+ final val Shell // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.Shell|{}Shell[0]
+ final fun (): com.mohamedrejeb.richeditor.highlight/CodeLanguage // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.Shell.|(){}[0]
+ final val Sql // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.Sql|{}Sql[0]
+ final fun (): com.mohamedrejeb.richeditor.highlight/CodeLanguage // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.Sql.|(){}[0]
+ final val Swift // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.Swift|{}Swift[0]
+ final fun (): com.mohamedrejeb.richeditor.highlight/CodeLanguage // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.Swift.|(){}[0]
+ final val TypeScript // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.TypeScript|{}TypeScript[0]
+ final fun (): com.mohamedrejeb.richeditor.highlight/CodeLanguage // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.TypeScript.|(){}[0]
+ final val Yaml // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.Yaml|{}Yaml[0]
+ final fun (): com.mohamedrejeb.richeditor.highlight/CodeLanguage // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.Yaml.|(){}[0]
+ final val all // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.all|{}all[0]
+ final fun (): kotlin.collections/List // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.all.|(){}[0]
+
+ final fun fromFileName(kotlin/String): com.mohamedrejeb.richeditor.highlight/CodeLanguage? // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.fromFileName|fromFileName(kotlin.String){}[0]
+ final fun fromName(kotlin/String): com.mohamedrejeb.richeditor.highlight/CodeLanguage? // com.mohamedrejeb.richeditor.highlight/CodeLanguage.Companion.fromName|fromName(kotlin.String){}[0]
+ }
+}
+
+final class com.mohamedrejeb.richeditor.highlight/CodeToken { // com.mohamedrejeb.richeditor.highlight/CodeToken|null[0]
+ constructor (kotlin/Int, kotlin/Int, com.mohamedrejeb.richeditor.highlight/CodeTokenKind) // com.mohamedrejeb.richeditor.highlight/CodeToken.|(kotlin.Int;kotlin.Int;com.mohamedrejeb.richeditor.highlight.CodeTokenKind){}[0]
+
+ final val end // com.mohamedrejeb.richeditor.highlight/CodeToken.end|{}end[0]
+ final fun (): kotlin/Int // com.mohamedrejeb.richeditor.highlight/CodeToken.end.|(){}[0]
+ final val kind // com.mohamedrejeb.richeditor.highlight/CodeToken.kind|{}kind[0]
+ final fun (): com.mohamedrejeb.richeditor.highlight/CodeTokenKind // com.mohamedrejeb.richeditor.highlight/CodeToken.kind.|(){}[0]
+ final val start // com.mohamedrejeb.richeditor.highlight/CodeToken.start|{}start[0]
+ final fun (): kotlin/Int // com.mohamedrejeb.richeditor.highlight/CodeToken.start.|(){}[0]
+
+ final fun equals(kotlin/Any?): kotlin/Boolean // com.mohamedrejeb.richeditor.highlight/CodeToken.equals|equals(kotlin.Any?){}[0]
+ final fun hashCode(): kotlin/Int // com.mohamedrejeb.richeditor.highlight/CodeToken.hashCode|hashCode(){}[0]
+ final fun toString(): kotlin/String // com.mohamedrejeb.richeditor.highlight/CodeToken.toString|toString(){}[0]
+}
+
final class com.mohamedrejeb.richeditor.model.history/RichTextHistory { // com.mohamedrejeb.richeditor.model.history/RichTextHistory|null[0]
final val canRedo // com.mohamedrejeb.richeditor.model.history/RichTextHistory.canRedo|{}canRedo[0]
final fun (): kotlin/Boolean // com.mohamedrejeb.richeditor.model.history/RichTextHistory.canRedo.|(){}[0]
@@ -735,6 +852,15 @@ final class com.mohamedrejeb.richeditor.model/RichTextConfig { // com.mohamedrej
final var autoLinkEnabled // com.mohamedrejeb.richeditor.model/RichTextConfig.autoLinkEnabled|{}autoLinkEnabled[0]
final fun (): kotlin/Boolean // com.mohamedrejeb.richeditor.model/RichTextConfig.autoLinkEnabled.|(){}[0]
final fun (kotlin/Boolean) // com.mohamedrejeb.richeditor.model/RichTextConfig.autoLinkEnabled.|(kotlin.Boolean){}[0]
+ final var codeBlockBackgroundColor // com.mohamedrejeb.richeditor.model/RichTextConfig.codeBlockBackgroundColor|{}codeBlockBackgroundColor[0]
+ final fun (): androidx.compose.ui.graphics/Color // com.mohamedrejeb.richeditor.model/RichTextConfig.codeBlockBackgroundColor.|(){}[0]
+ final fun (androidx.compose.ui.graphics/Color) // com.mohamedrejeb.richeditor.model/RichTextConfig.codeBlockBackgroundColor.|(androidx.compose.ui.graphics.Color){}[0]
+ final var codeBlockColors // com.mohamedrejeb.richeditor.model/RichTextConfig.codeBlockColors|{}codeBlockColors[0]
+ final fun (): com.mohamedrejeb.richeditor.highlight/CodeBlockColors // com.mohamedrejeb.richeditor.model/RichTextConfig.codeBlockColors.|(){}[0]
+ final fun (com.mohamedrejeb.richeditor.highlight/CodeBlockColors) // com.mohamedrejeb.richeditor.model/RichTextConfig.codeBlockColors.|(com.mohamedrejeb.richeditor.highlight.CodeBlockColors){}[0]
+ final var codeBlockFontFamily // com.mohamedrejeb.richeditor.model/RichTextConfig.codeBlockFontFamily|{}codeBlockFontFamily[0]
+ final fun (): androidx.compose.ui.text.font/FontFamily // com.mohamedrejeb.richeditor.model/RichTextConfig.codeBlockFontFamily.|(){}[0]
+ final fun (androidx.compose.ui.text.font/FontFamily) // com.mohamedrejeb.richeditor.model/RichTextConfig.codeBlockFontFamily.|(androidx.compose.ui.text.font.FontFamily){}[0]
final var codeSpanBackgroundColor // com.mohamedrejeb.richeditor.model/RichTextConfig.codeSpanBackgroundColor|{}codeSpanBackgroundColor[0]
final fun (): androidx.compose.ui.graphics/Color // com.mohamedrejeb.richeditor.model/RichTextConfig.codeSpanBackgroundColor.|(){}[0]
final fun (androidx.compose.ui.graphics/Color) // com.mohamedrejeb.richeditor.model/RichTextConfig.codeSpanBackgroundColor.|(androidx.compose.ui.graphics.Color){}[0]
@@ -1017,6 +1143,11 @@ final class com.mohamedrejeb.richeditor.ui.material3/RichTextEditorColors { // c
final fun hashCode(): kotlin/Int // com.mohamedrejeb.richeditor.ui.material3/RichTextEditorColors.hashCode|hashCode(){}[0]
}
+final object com.mohamedrejeb.richeditor.highlight/CodeHighlighter { // com.mohamedrejeb.richeditor.highlight/CodeHighlighter|null[0]
+ final fun tokenize(kotlin/String, com.mohamedrejeb.richeditor.highlight/CodeLanguage): kotlin.collections/List // com.mohamedrejeb.richeditor.highlight/CodeHighlighter.tokenize|tokenize(kotlin.String;com.mohamedrejeb.richeditor.highlight.CodeLanguage){}[0]
+ final fun tokenizeLines(kotlin.collections/List, com.mohamedrejeb.richeditor.highlight/CodeLanguage): kotlin.collections/List> // com.mohamedrejeb.richeditor.highlight/CodeHighlighter.tokenizeLines|tokenizeLines(kotlin.collections.List;com.mohamedrejeb.richeditor.highlight.CodeLanguage){}[0]
+}
+
final object com.mohamedrejeb.richeditor.model/DefaultImageLoader : com.mohamedrejeb.richeditor.model/ImageLoader { // com.mohamedrejeb.richeditor.model/DefaultImageLoader|null[0]
final fun load(kotlin/Any, androidx.compose.runtime/Composer?, kotlin/Int): com.mohamedrejeb.richeditor.model/ImageData? // com.mohamedrejeb.richeditor.model/DefaultImageLoader.load|load(kotlin.Any;androidx.compose.runtime.Composer?;kotlin.Int){}[0]
}
@@ -1050,6 +1181,7 @@ final object com.mohamedrejeb.richeditor.ui.material3/RichTextEditorDefaults { /
}
final val com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextBlock$stableprop // com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextBlock$stableprop|#static{}com_mohamedrejeb_richeditor_document_RichTextBlock$stableprop[0]
+final val com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextBlockType_CodeBlock$stableprop // com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextBlockType_CodeBlock$stableprop|#static{}com_mohamedrejeb_richeditor_document_RichTextBlockType_CodeBlock$stableprop[0]
final val com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextBlockType_ListItem$stableprop // com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextBlockType_ListItem$stableprop|#static{}com_mohamedrejeb_richeditor_document_RichTextBlockType_ListItem$stableprop[0]
final val com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextBlockType_Paragraph$stableprop // com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextBlockType_Paragraph$stableprop|#static{}com_mohamedrejeb_richeditor_document_RichTextBlockType_Paragraph$stableprop[0]
final val com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextDocument$stableprop // com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextDocument$stableprop|#static{}com_mohamedrejeb_richeditor_document_RichTextDocument$stableprop[0]
@@ -1070,6 +1202,10 @@ final val com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_docum
final val com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextSpanMark_Token$stableprop // com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextSpanMark_Token$stableprop|#static{}com_mohamedrejeb_richeditor_document_RichTextSpanMark_Token$stableprop[0]
final val com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextSpanMark_Underline$stableprop // com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextSpanMark_Underline$stableprop|#static{}com_mohamedrejeb_richeditor_document_RichTextSpanMark_Underline$stableprop[0]
final val com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextSpanMark_Unknown$stableprop // com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextSpanMark_Unknown$stableprop|#static{}com_mohamedrejeb_richeditor_document_RichTextSpanMark_Unknown$stableprop[0]
+final val com.mohamedrejeb.richeditor.highlight/com_mohamedrejeb_richeditor_highlight_CodeBlockColors$stableprop // com.mohamedrejeb.richeditor.highlight/com_mohamedrejeb_richeditor_highlight_CodeBlockColors$stableprop|#static{}com_mohamedrejeb_richeditor_highlight_CodeBlockColors$stableprop[0]
+final val com.mohamedrejeb.richeditor.highlight/com_mohamedrejeb_richeditor_highlight_CodeHighlighter$stableprop // com.mohamedrejeb.richeditor.highlight/com_mohamedrejeb_richeditor_highlight_CodeHighlighter$stableprop|#static{}com_mohamedrejeb_richeditor_highlight_CodeHighlighter$stableprop[0]
+final val com.mohamedrejeb.richeditor.highlight/com_mohamedrejeb_richeditor_highlight_CodeLanguage$stableprop // com.mohamedrejeb.richeditor.highlight/com_mohamedrejeb_richeditor_highlight_CodeLanguage$stableprop|#static{}com_mohamedrejeb_richeditor_highlight_CodeLanguage$stableprop[0]
+final val com.mohamedrejeb.richeditor.highlight/com_mohamedrejeb_richeditor_highlight_CodeToken$stableprop // com.mohamedrejeb.richeditor.highlight/com_mohamedrejeb_richeditor_highlight_CodeToken$stableprop|#static{}com_mohamedrejeb_richeditor_highlight_CodeToken$stableprop[0]
final val com.mohamedrejeb.richeditor.model.history/com_mohamedrejeb_richeditor_model_history_CommitTrigger_Delete$stableprop // com.mohamedrejeb.richeditor.model.history/com_mohamedrejeb_richeditor_model_history_CommitTrigger_Delete$stableprop|#static{}com_mohamedrejeb_richeditor_model_history_CommitTrigger_Delete$stableprop[0]
final val com.mohamedrejeb.richeditor.model.history/com_mohamedrejeb_richeditor_model_history_CommitTrigger_Formatting$stableprop // com.mohamedrejeb.richeditor.model.history/com_mohamedrejeb_richeditor_model_history_CommitTrigger_Formatting$stableprop|#static{}com_mohamedrejeb_richeditor_model_history_CommitTrigger_Formatting$stableprop[0]
final val com.mohamedrejeb.richeditor.model.history/com_mohamedrejeb_richeditor_model_history_CommitTrigger_LineBreak$stableprop // com.mohamedrejeb.richeditor.model.history/com_mohamedrejeb_richeditor_model_history_CommitTrigger_LineBreak$stableprop|#static{}com_mohamedrejeb_richeditor_model_history_CommitTrigger_LineBreak$stableprop[0]
@@ -1122,6 +1258,7 @@ final fun (androidx.compose.ui.text/TextLayoutResult).com.mohamedrejeb.richedito
final fun (kotlin/Float).com.mohamedrejeb.richeditor.utils/maxDecimals(kotlin/Int): kotlin/Float // com.mohamedrejeb.richeditor.utils/maxDecimals|maxDecimals@kotlin.Float(kotlin.Int){}[0]
final fun <#A: kotlin/Any?> com.mohamedrejeb.richeditor.ui.material3/TriggerSuggestions(com.mohamedrejeb.richeditor.model/RichTextState, kotlin/String, kotlin/Function1>, kotlin/Function1<#A, com.mohamedrejeb.richeditor.model/RichSpanStyle.Token>, androidx.compose.ui/Modifier?, androidx.compose.ui.unit/Dp, androidx.compose.ui.graphics/Color, androidx.compose.ui.graphics/Color, androidx.compose.ui.graphics/Color, androidx.compose.ui.graphics/Shape?, kotlin/Int, kotlin/Function3<#A, androidx.compose.runtime/Composer, kotlin/Int, kotlin/Unit>, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int, kotlin/Int) // com.mohamedrejeb.richeditor.ui.material3/TriggerSuggestions|TriggerSuggestions(com.mohamedrejeb.richeditor.model.RichTextState;kotlin.String;kotlin.Function1>;kotlin.Function1<0:0,com.mohamedrejeb.richeditor.model.RichSpanStyle.Token>;androidx.compose.ui.Modifier?;androidx.compose.ui.unit.Dp;androidx.compose.ui.graphics.Color;androidx.compose.ui.graphics.Color;androidx.compose.ui.graphics.Color;androidx.compose.ui.graphics.Shape?;kotlin.Int;kotlin.Function3<0:0,androidx.compose.runtime.Composer,kotlin.Int,kotlin.Unit>;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int;kotlin.Int){0§}[0]
final fun com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextBlock$stableprop_getter(): kotlin/Int // com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextBlock$stableprop_getter|com_mohamedrejeb_richeditor_document_RichTextBlock$stableprop_getter(){}[0]
+final fun com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextBlockType_CodeBlock$stableprop_getter(): kotlin/Int // com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextBlockType_CodeBlock$stableprop_getter|com_mohamedrejeb_richeditor_document_RichTextBlockType_CodeBlock$stableprop_getter(){}[0]
final fun com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextBlockType_ListItem$stableprop_getter(): kotlin/Int // com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextBlockType_ListItem$stableprop_getter|com_mohamedrejeb_richeditor_document_RichTextBlockType_ListItem$stableprop_getter(){}[0]
final fun com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextBlockType_Paragraph$stableprop_getter(): kotlin/Int // com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextBlockType_Paragraph$stableprop_getter|com_mohamedrejeb_richeditor_document_RichTextBlockType_Paragraph$stableprop_getter(){}[0]
final fun com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextDocument$stableprop_getter(): kotlin/Int // com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextDocument$stableprop_getter|com_mohamedrejeb_richeditor_document_RichTextDocument$stableprop_getter(){}[0]
@@ -1142,6 +1279,11 @@ final fun com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_docum
final fun com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextSpanMark_Token$stableprop_getter(): kotlin/Int // com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextSpanMark_Token$stableprop_getter|com_mohamedrejeb_richeditor_document_RichTextSpanMark_Token$stableprop_getter(){}[0]
final fun com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextSpanMark_Underline$stableprop_getter(): kotlin/Int // com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextSpanMark_Underline$stableprop_getter|com_mohamedrejeb_richeditor_document_RichTextSpanMark_Underline$stableprop_getter(){}[0]
final fun com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextSpanMark_Unknown$stableprop_getter(): kotlin/Int // com.mohamedrejeb.richeditor.document/com_mohamedrejeb_richeditor_document_RichTextSpanMark_Unknown$stableprop_getter|com_mohamedrejeb_richeditor_document_RichTextSpanMark_Unknown$stableprop_getter(){}[0]
+final fun com.mohamedrejeb.richeditor.highlight/com_mohamedrejeb_richeditor_highlight_CodeBlockColors$stableprop_getter(): kotlin/Int // com.mohamedrejeb.richeditor.highlight/com_mohamedrejeb_richeditor_highlight_CodeBlockColors$stableprop_getter|com_mohamedrejeb_richeditor_highlight_CodeBlockColors$stableprop_getter(){}[0]
+final fun com.mohamedrejeb.richeditor.highlight/com_mohamedrejeb_richeditor_highlight_CodeHighlighter$stableprop_getter(): kotlin/Int // com.mohamedrejeb.richeditor.highlight/com_mohamedrejeb_richeditor_highlight_CodeHighlighter$stableprop_getter|com_mohamedrejeb_richeditor_highlight_CodeHighlighter$stableprop_getter(){}[0]
+final fun com.mohamedrejeb.richeditor.highlight/com_mohamedrejeb_richeditor_highlight_CodeLanguage$stableprop_getter(): kotlin/Int // com.mohamedrejeb.richeditor.highlight/com_mohamedrejeb_richeditor_highlight_CodeLanguage$stableprop_getter|com_mohamedrejeb_richeditor_highlight_CodeLanguage$stableprop_getter(){}[0]
+final fun com.mohamedrejeb.richeditor.highlight/com_mohamedrejeb_richeditor_highlight_CodeToken$stableprop_getter(): kotlin/Int // com.mohamedrejeb.richeditor.highlight/com_mohamedrejeb_richeditor_highlight_CodeToken$stableprop_getter|com_mohamedrejeb_richeditor_highlight_CodeToken$stableprop_getter(){}[0]
+final fun com.mohamedrejeb.richeditor.highlight/highlightCode(kotlin/String, com.mohamedrejeb.richeditor.highlight/CodeLanguage?, com.mohamedrejeb.richeditor.highlight/CodeBlockColors = ...): androidx.compose.ui.text/AnnotatedString // com.mohamedrejeb.richeditor.highlight/highlightCode|highlightCode(kotlin.String;com.mohamedrejeb.richeditor.highlight.CodeLanguage?;com.mohamedrejeb.richeditor.highlight.CodeBlockColors){}[0]
final fun com.mohamedrejeb.richeditor.model.history/com_mohamedrejeb_richeditor_model_history_CommitTrigger_Delete$stableprop_getter(): kotlin/Int // com.mohamedrejeb.richeditor.model.history/com_mohamedrejeb_richeditor_model_history_CommitTrigger_Delete$stableprop_getter|com_mohamedrejeb_richeditor_model_history_CommitTrigger_Delete$stableprop_getter(){}[0]
final fun com.mohamedrejeb.richeditor.model.history/com_mohamedrejeb_richeditor_model_history_CommitTrigger_Formatting$stableprop_getter(): kotlin/Int // com.mohamedrejeb.richeditor.model.history/com_mohamedrejeb_richeditor_model_history_CommitTrigger_Formatting$stableprop_getter|com_mohamedrejeb_richeditor_model_history_CommitTrigger_Formatting$stableprop_getter(){}[0]
final fun com.mohamedrejeb.richeditor.model.history/com_mohamedrejeb_richeditor_model_history_CommitTrigger_LineBreak$stableprop_getter(): kotlin/Int // com.mohamedrejeb.richeditor.model.history/com_mohamedrejeb_richeditor_model_history_CommitTrigger_LineBreak$stableprop_getter|com_mohamedrejeb_richeditor_model_history_CommitTrigger_LineBreak$stableprop_getter(){}[0]
@@ -1188,6 +1330,7 @@ final fun com.mohamedrejeb.richeditor.ui.material3/RichText(com.mohamedrejeb.ric
final fun com.mohamedrejeb.richeditor.ui.material3/RichTextEditor(com.mohamedrejeb.richeditor.model/RichTextState, androidx.compose.ui/Modifier?, kotlin/Boolean, kotlin/Boolean, androidx.compose.ui.text/TextStyle?, kotlin/Function2?, kotlin/Function2?, kotlin/Function2?, kotlin/Function2?, kotlin/Function2?, kotlin/Boolean, androidx.compose.foundation.text/KeyboardOptions?, androidx.compose.foundation.text/KeyboardActions?, kotlin/Boolean, kotlin/Int, kotlin/Int, kotlin/Int, kotlin/Function1?, androidx.compose.foundation.interaction/MutableInteractionSource?, androidx.compose.ui.graphics/Shape?, com.mohamedrejeb.richeditor.ui.material3/RichTextEditorColors?, androidx.compose.foundation.layout/PaddingValues?, com.mohamedrejeb.richeditor.ui/UndoBehavior?, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int, kotlin/Int, kotlin/Int) // com.mohamedrejeb.richeditor.ui.material3/RichTextEditor|RichTextEditor(com.mohamedrejeb.richeditor.model.RichTextState;androidx.compose.ui.Modifier?;kotlin.Boolean;kotlin.Boolean;androidx.compose.ui.text.TextStyle?;kotlin.Function2?;kotlin.Function2?;kotlin.Function2?;kotlin.Function2?;kotlin.Function2?;kotlin.Boolean;androidx.compose.foundation.text.KeyboardOptions?;androidx.compose.foundation.text.KeyboardActions?;kotlin.Boolean;kotlin.Int;kotlin.Int;kotlin.Int;kotlin.Function1?;androidx.compose.foundation.interaction.MutableInteractionSource?;androidx.compose.ui.graphics.Shape?;com.mohamedrejeb.richeditor.ui.material3.RichTextEditorColors?;androidx.compose.foundation.layout.PaddingValues?;com.mohamedrejeb.richeditor.ui.UndoBehavior?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int;kotlin.Int;kotlin.Int){}[0]
final fun com.mohamedrejeb.richeditor.ui.material3/com_mohamedrejeb_richeditor_ui_material3_RichTextEditorColors$stableprop_getter(): kotlin/Int // com.mohamedrejeb.richeditor.ui.material3/com_mohamedrejeb_richeditor_ui_material3_RichTextEditorColors$stableprop_getter|com_mohamedrejeb_richeditor_ui_material3_RichTextEditorColors$stableprop_getter(){}[0]
final fun com.mohamedrejeb.richeditor.ui.material3/com_mohamedrejeb_richeditor_ui_material3_RichTextEditorDefaults$stableprop_getter(): kotlin/Int // com.mohamedrejeb.richeditor.ui.material3/com_mohamedrejeb_richeditor_ui_material3_RichTextEditorDefaults$stableprop_getter|com_mohamedrejeb_richeditor_ui_material3_RichTextEditorDefaults$stableprop_getter(){}[0]
+final fun com.mohamedrejeb.richeditor.ui/BasicCodeText(kotlin/String, com.mohamedrejeb.richeditor.highlight/CodeLanguage?, androidx.compose.ui/Modifier?, androidx.compose.ui.text/TextStyle?, com.mohamedrejeb.richeditor.highlight/CodeBlockColors?, kotlin/Boolean, kotlin/Function1?, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int) // com.mohamedrejeb.richeditor.ui/BasicCodeText|BasicCodeText(kotlin.String;com.mohamedrejeb.richeditor.highlight.CodeLanguage?;androidx.compose.ui.Modifier?;androidx.compose.ui.text.TextStyle?;com.mohamedrejeb.richeditor.highlight.CodeBlockColors?;kotlin.Boolean;kotlin.Function1?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int){}[0]
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.style/TextOverflow, kotlin/Boolean, kotlin/Int, kotlin/Int, kotlin.collections/Map?, com.mohamedrejeb.richeditor.model/ImageLoader?, com.mohamedrejeb.richeditor.model/TokenClickHandler?, com.mohamedrejeb.richeditor.model/TokenHoverHandler?, androidx.compose.runtime/Composer?, kotlin/Int, 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.style.TextOverflow;kotlin.Boolean;kotlin.Int;kotlin.Int;kotlin.collections.Map?;com.mohamedrejeb.richeditor.model.ImageLoader?;com.mohamedrejeb.richeditor.model.TokenClickHandler?;com.mohamedrejeb.richeditor.model.TokenHoverHandler?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int;kotlin.Int){}[0]
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.style/TextOverflow?, kotlin/Boolean, kotlin/Int, kotlin/Int, kotlin.collections/Map?, com.mohamedrejeb.richeditor.model/ImageLoader?, com.mohamedrejeb.richeditor.model/TokenClickHandler?, com.mohamedrejeb.richeditor.model/TokenHoverHandler?, androidx.compose.runtime/Composer?, kotlin/Int, 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.style.TextOverflow?;kotlin.Boolean;kotlin.Int;kotlin.Int;kotlin.collections.Map?;com.mohamedrejeb.richeditor.model.ImageLoader?;com.mohamedrejeb.richeditor.model.TokenClickHandler?;com.mohamedrejeb.richeditor.model.TokenHoverHandler?;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/Boolean, kotlin/Int, kotlin/Int, kotlin/Int, kotlin/Function1?, androidx.compose.foundation.interaction/MutableInteractionSource?, androidx.compose.ui.graphics/Brush?, com.mohamedrejeb.richeditor.ui/UndoBehavior?, kotlin/Function3, 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.foundation.interaction.MutableInteractionSource?;androidx.compose.ui.graphics.Brush?;com.mohamedrejeb.richeditor.ui.UndoBehavior?;kotlin.Function3,androidx.compose.runtime.Composer,kotlin.Int,kotlin.Unit>?;androidx.compose.foundation.layout.PaddingValues;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int;kotlin.Int){}[0]
diff --git a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/codeblocks/CodeBlocksSampleScreen.kt b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/codeblocks/CodeBlocksSampleScreen.kt
new file mode 100644
index 00000000..b03f0d52
--- /dev/null
+++ b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/codeblocks/CodeBlocksSampleScreen.kt
@@ -0,0 +1,219 @@
+package com.mohamedrejeb.richeditor.sample.common.codeblocks
+
+import androidx.compose.foundation.background
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.width
+import androidx.compose.foundation.rememberScrollState
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.foundation.verticalScroll
+import androidx.compose.material3.MaterialTheme
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.remember
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.draw.clip
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.text.AnnotatedString
+import androidx.compose.ui.text.SpanStyle
+import androidx.compose.ui.text.TextStyle
+import androidx.compose.ui.text.buildAnnotatedString
+import androidx.compose.ui.text.font.FontFamily
+import androidx.compose.ui.text.font.FontStyle
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
+import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi
+import com.mohamedrejeb.richeditor.highlight.CodeBlockColors
+import com.mohamedrejeb.richeditor.highlight.CodeHighlighter
+import com.mohamedrejeb.richeditor.highlight.CodeLanguage
+import com.mohamedrejeb.richeditor.model.RichTextState
+import com.mohamedrejeb.richeditor.sample.common.components.SampleScaffold
+import com.mohamedrejeb.richeditor.ui.BasicCodeText
+import com.mohamedrejeb.richeditor.ui.material3.RichText
+
+private val replyMarkdown = """
+Here is a small **Kotlin** function and the same idea in *Python*:
+
+```kotlin
+/* Greets everyone
+ in the list. */
+@Composable
+fun Greeting(names: List) {
+ for (name in names) {
+ Text("Hello, ${'$'}name!") // one line each
+ }
+}
+```
+
+```python
+def greet(names):
+ ${"\"\"\""}Greets everyone in the list.${"\"\"\""}
+ for name in names:
+ print(f"Hello, {name}!") # one line each
+```
+
+Both walk the list once.
+""".trimIndent()
+
+private const val Snippet =
+ "val message = listOf(\"a fairly long line\", \"that does not fit\", \"and scrolls sideways\").joinToString(separator = \", \") { it.uppercase() }\n" +
+ "println(message)"
+
+private enum class DiffKind { Same, Added, Removed }
+
+private class DiffLine(val kind: DiffKind, val text: String)
+
+private const val DiffFileName = "Greeter.kt"
+
+private val diffLines = listOf(
+ DiffLine(DiffKind.Same, "class Greeter(private val names: List) {"),
+ DiffLine(DiffKind.Same, " /* Greets everyone"),
+ DiffLine(DiffKind.Same, " in the list. */"),
+ DiffLine(DiffKind.Removed, " fun greet() = names.forEach { println(\"Hi \$it\") }"),
+ DiffLine(DiffKind.Added, " fun greet(greeting: String = \"Hello\") ="),
+ DiffLine(DiffKind.Added, " names.forEach { println(\"\$greeting, \$it!\") }"),
+ DiffLine(DiffKind.Same, "}"),
+)
+
+private val AddedBackground = Color(0x3322C55E)
+private val RemovedBackground = Color(0x33EF4444)
+
+@OptIn(ExperimentalRichTextApi::class)
+@Composable
+fun CodeBlocksSampleScreen(navigateBack: () -> Unit) {
+ val scheme = MaterialTheme.colorScheme
+ val colors = remember(scheme) {
+ CodeBlockColors(
+ keyword = SpanStyle(color = scheme.primary),
+ string = SpanStyle(color = scheme.tertiary),
+ number = SpanStyle(color = scheme.secondary),
+ comment = SpanStyle(color = scheme.outline, fontStyle = FontStyle.Italic),
+ annotation = SpanStyle(color = scheme.secondary),
+ )
+ }
+
+ SampleScaffold(
+ title = "Code blocks",
+ navigateBack = navigateBack,
+ ) { paddingValues ->
+ Column(
+ verticalArrangement = Arrangement.spacedBy(12.dp),
+ modifier = Modifier
+ .fillMaxSize()
+ .padding(paddingValues)
+ .padding(horizontal = 20.dp)
+ .verticalScroll(rememberScrollState()),
+ ) {
+ Spacer(Modifier.height(8.dp))
+
+ SectionTitle("Markdown with code blocks", "RichText draws fenced code coloured by its language.")
+ val state = remember(scheme, colors) {
+ RichTextState().apply {
+ config.codeBlockBackgroundColor = scheme.surfaceVariant
+ config.codeBlockColors = colors
+ setMarkdown(replyMarkdown)
+ }
+ }
+ RichText(state = state, modifier = Modifier.fillMaxWidth())
+
+ SectionTitle("Code alone", "BasicCodeText needs no state. A long line scrolls sideways.")
+ BasicCodeText(
+ code = Snippet,
+ language = CodeLanguage.Kotlin,
+ colors = colors,
+ style = CodeStyle.copy(color = scheme.onSurface),
+ modifier = Modifier
+ .fillMaxWidth()
+ .background(scheme.surfaceVariant, RoundedCornerShape(8.dp))
+ .padding(12.dp),
+ )
+
+ SectionTitle("A diff view", "Rows drawn by the app and coloured with CodeHighlighter.tokenizeLines.")
+ DiffView(colors)
+
+ Spacer(Modifier.height(24.dp))
+ }
+ }
+}
+
+@Composable
+private fun SectionTitle(title: String, description: String) {
+ Column(verticalArrangement = Arrangement.spacedBy(2.dp), modifier = Modifier.padding(top = 12.dp)) {
+ Text(title, style = MaterialTheme.typography.titleMedium)
+ Text(description, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant)
+ }
+}
+
+@OptIn(ExperimentalRichTextApi::class)
+@Composable
+private fun DiffView(colors: CodeBlockColors) {
+ val scheme = MaterialTheme.colorScheme
+ val rows = remember(colors) { diffRows(colors) }
+
+ Column(
+ modifier = Modifier
+ .fillMaxWidth()
+ .clip(RoundedCornerShape(8.dp))
+ .background(scheme.surfaceVariant),
+ ) {
+ diffLines.forEachIndexed { index, line ->
+ Row(
+ modifier = Modifier
+ .fillMaxWidth()
+ .background(
+ when (line.kind) {
+ DiffKind.Same -> Color.Transparent
+ DiffKind.Added -> AddedBackground
+ DiffKind.Removed -> RemovedBackground
+ }
+ )
+ .padding(horizontal = 12.dp, vertical = 2.dp),
+ ) {
+ Text(
+ text = when (line.kind) {
+ DiffKind.Same -> " "
+ DiffKind.Added -> "+"
+ DiffKind.Removed -> "-"
+ },
+ style = CodeStyle,
+ color = scheme.onSurfaceVariant,
+ modifier = Modifier.width(20.dp),
+ )
+ Text(text = rows[index], style = CodeStyle, color = scheme.onSurface)
+ }
+ }
+ }
+}
+
+/**
+ * The text of each diff row with its token styles. The old and the new side are tokenized apart,
+ * each as the continuous code it is, so a removed line never changes how an added one is read.
+ */
+@OptIn(ExperimentalRichTextApi::class)
+private fun diffRows(colors: CodeBlockColors): List {
+ val language = CodeLanguage.fromFileName(DiffFileName) ?: return diffLines.map { AnnotatedString(it.text) }
+ val oldSide = diffLines.withIndex().filter { it.value.kind != DiffKind.Added }
+ val newSide = diffLines.withIndex().filter { it.value.kind != DiffKind.Removed }
+ val oldTokens = CodeHighlighter.tokenizeLines(oldSide.map { it.value.text }, language)
+ val newTokens = CodeHighlighter.tokenizeLines(newSide.map { it.value.text }, language)
+ val tokensByRow =
+ oldSide.mapIndexed { position, row -> row.index to oldTokens[position] }.toMap() +
+ newSide.mapIndexed { position, row -> row.index to newTokens[position] }.toMap()
+
+ return diffLines.mapIndexed { index, line ->
+ buildAnnotatedString {
+ append(line.text)
+ tokensByRow[index].orEmpty().forEach { token ->
+ addStyle(colors.styleOf(token.kind), token.start, token.end)
+ }
+ }
+ }
+}
+
+private val CodeStyle = TextStyle(fontFamily = FontFamily.Monospace, fontSize = 13.sp)
diff --git a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/home/HomeScreen.kt b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/home/HomeScreen.kt
index 501e2669..916e6ef5 100644
--- a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/home/HomeScreen.kt
+++ b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/home/HomeScreen.kt
@@ -22,6 +22,7 @@ import androidx.compose.material.icons.outlined.AlternateEmail
import androidx.compose.material.icons.outlined.Apps
import androidx.compose.material.icons.outlined.BugReport
import androidx.compose.material.icons.outlined.Code
+import androidx.compose.material.icons.outlined.DataObject
import androidx.compose.material.icons.outlined.History
import androidx.compose.material.icons.outlined.Image
import androidx.compose.material.icons.outlined.Link
@@ -66,6 +67,7 @@ fun HomeScreen(
navigateToClaude: () -> Unit,
navigateToExpandable: () -> Unit,
navigateToEditorLab: () -> Unit,
+ navigateToCodeBlocks: () -> Unit,
) {
SampleScaffold(
title = "Compose Rich Editor",
@@ -239,6 +241,16 @@ fun HomeScreen(
)
}
+ item {
+ FeatureCard(
+ title = "Code blocks",
+ description = "Fenced code coloured by language, code on its own with BasicCodeText, and a diff view built on the tokenizer.",
+ icon = Icons.Outlined.DataObject,
+ accent = SampleAccents.Violet,
+ onClick = navigateToCodeBlocks,
+ )
+ }
+
item { SectionSpacer() }
item {
diff --git a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/navigation/NavGraph.kt b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/navigation/NavGraph.kt
index e726df90..6fcb4ebc 100644
--- a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/navigation/NavGraph.kt
+++ b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/navigation/NavGraph.kt
@@ -11,6 +11,7 @@ import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import com.mohamedrejeb.richeditor.sample.common.claude.ClaudeDemoScreen
+import com.mohamedrejeb.richeditor.sample.common.codeblocks.CodeBlocksSampleScreen
import com.mohamedrejeb.richeditor.sample.common.examples.RealExamplesScreen
import com.mohamedrejeb.richeditor.sample.common.expandable.ExpandableTextSampleScreen
import com.mohamedrejeb.richeditor.sample.common.github.GitHubDemoScreen
@@ -45,6 +46,7 @@ private const val HEADINGS_ROUTE = "headings"
private const val CLAUDE_ROUTE = "claude"
private const val EXPANDABLE_ROUTE = "expandable"
private const val EDITOR_LAB_ROUTE = "editorLab"
+private const val CODE_BLOCKS_ROUTE = "codeBlocks"
@Composable
fun NavGraph() {
@@ -82,6 +84,7 @@ fun NavGraph() {
navigateToClaude = { navController.navigate(CLAUDE_ROUTE) },
navigateToExpandable = { navController.navigate(EXPANDABLE_ROUTE) },
navigateToEditorLab = { navController.navigate(EDITOR_LAB_ROUTE) },
+ navigateToCodeBlocks = { navController.navigate(CODE_BLOCKS_ROUTE) },
)
}
@@ -184,5 +187,11 @@ fun NavGraph() {
navigateBack = { navController.popBackStack() }
)
}
+
+ composable(CODE_BLOCKS_ROUTE) {
+ CodeBlocksSampleScreen(
+ navigateBack = { navController.popBackStack() }
+ )
+ }
}
}
From afb0cea84ea08ccbc6d28b00dd60a3c89c0b2f26 Mon Sep 17 00:00:00 2001
From: MohamedRejeb
Date: Thu, 8 Oct 2026 23:26:44 +0100
Subject: [PATCH 12/16] fix: keep a pasted code block whole and paste into a
block as plain code
---
.../richeditor/model/RichTextState.kt | 48 ++++-
.../richeditor/paragraph/CodeBlocks.kt | 9 +
.../model/CodeBlockClipboardTest.kt | 199 ++++++++++++++++++
.../richeditor/clipboard/CodeBlockCopyTest.kt | 164 +++++++++++++++
4 files changed, 409 insertions(+), 11 deletions(-)
create mode 100644 richeditor-compose/src/commonTest/kotlin/com/mohamedrejeb/richeditor/model/CodeBlockClipboardTest.kt
create mode 100644 richeditor-compose/src/desktopTest/kotlin/com/mohamedrejeb/richeditor/clipboard/CodeBlockCopyTest.kt
diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/model/RichTextState.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/model/RichTextState.kt
index 0aa84218..68dcd055 100644
--- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/model/RichTextState.kt
+++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/model/RichTextState.kt
@@ -46,6 +46,7 @@ import com.mohamedrejeb.richeditor.model.trigger.Trigger
import com.mohamedrejeb.richeditor.model.trigger.TriggerQuery
import com.mohamedrejeb.richeditor.model.trigger.detectActiveTrigger
import com.mohamedrejeb.richeditor.paragraph.RichParagraph
+import com.mohamedrejeb.richeditor.paragraph.asCodeLinesOf
import com.mohamedrejeb.richeditor.paragraph.baseSpanStyle
import com.mohamedrejeb.richeditor.paragraph.type.*
import com.mohamedrejeb.richeditor.platform.currentPlatform
@@ -6169,8 +6170,6 @@ public class RichTextState internal constructor(
p.children.add(RichSpan(paragraph = p))
}
- val firstNewParagraph = newParagraphs.first()
-
val richSpan = getRichSpanByTextIndex(
textIndex = position - 1,
ignoreCustomFiltering = true,
@@ -6180,6 +6179,11 @@ public class RichTextState internal constructor(
val targetParagraph = richSpan.paragraph
val paragraphIndex = richParagraphList.indexOf(targetParagraph)
+ // Whatever lands inside a code block becomes plain lines of that block.
+ val targetCodeBlock = targetParagraph.type as? CodeBlock
+ val newParagraphs = if (targetCodeBlock == null) newParagraphs else newParagraphs.asCodeLinesOf(targetCodeBlock)
+ val firstNewParagraph = newParagraphs.first()
+
val sliceIndex = max(position, richSpan.textRange.min)
val targetParagraphFirstHalf = targetParagraph
@@ -6189,7 +6193,11 @@ public class RichTextState internal constructor(
removeSliceIndex = false,
)
- if (targetParagraphFirstHalf.isEmpty() && firstNewParagraph.isNotEmpty()) {
+ if (
+ targetCodeBlock == null &&
+ targetParagraphFirstHalf.isEmpty() &&
+ (firstNewParagraph.isNotEmpty() || firstNewParagraph.type is CodeBlock)
+ ) {
targetParagraphFirstHalf.paragraphStyle = firstNewParagraph.paragraphStyle
targetParagraphFirstHalf.type = firstNewParagraph.type
}
@@ -6209,22 +6217,40 @@ public class RichTextState internal constructor(
val lastNewParagraph = newParagraphs.last()
+ // A code block pasted into ordinary text stays whole: the text is split around it
+ // and never joins its first or last line.
+ val keepsFirstWhole = targetCodeBlock == null &&
+ firstNewParagraph.type is CodeBlock && firstNewParagraph.type != targetParagraphFirstHalf.type
+ val keepsLastWhole = targetCodeBlock == null &&
+ lastNewParagraph.type is CodeBlock && targetParagraphSecondHalf.isNotEmpty()
+ val firstIndex = if (keepsFirstWhole) paragraphIndex + 1 else paragraphIndex
+
// Before position + First pasted paragraph
- firstNewParagraph.updateChildrenParagraph(targetParagraphFirstHalf)
- targetParagraphFirstHalf.children.addAll(firstNewParagraph.children)
- targetParagraphFirstHalf.removeEmptyChildren()
+ if (keepsFirstWhole) {
+ richParagraphList.add(firstIndex, firstNewParagraph)
+ } else {
+ firstNewParagraph.updateChildrenParagraph(targetParagraphFirstHalf)
+ targetParagraphFirstHalf.children.addAll(firstNewParagraph.children)
+ targetParagraphFirstHalf.removeEmptyChildren()
+ }
// Pasted paragraphs between first and last
if (newParagraphs.size >= 3) {
val middleParagraphs = newParagraphs.subList(1, newParagraphs.size - 1)
- richParagraphList.addAll(paragraphIndex + 1, middleParagraphs)
+ richParagraphList.addAll(firstIndex + 1, middleParagraphs)
}
// Last pasted paragraph + After position
- targetParagraphSecondHalf.updateChildrenParagraph(lastNewParagraph)
- lastNewParagraph.children.addAll(targetParagraphSecondHalf.children)
- lastNewParagraph.removeEmptyChildren()
- richParagraphList.add(paragraphIndex + newParagraphs.size - 1, lastNewParagraph)
+ val lastIndex = firstIndex + newParagraphs.size - 1
+ if (keepsLastWhole) {
+ richParagraphList.add(lastIndex, lastNewParagraph)
+ richParagraphList.add(lastIndex + 1, targetParagraphSecondHalf)
+ } else {
+ targetParagraphSecondHalf.updateChildrenParagraph(lastNewParagraph)
+ lastNewParagraph.children.addAll(targetParagraphSecondHalf.children)
+ lastNewParagraph.removeEmptyChildren()
+ richParagraphList.add(lastIndex, lastNewParagraph)
+ }
}
// Update the state
diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/paragraph/CodeBlocks.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/paragraph/CodeBlocks.kt
index 613b864a..4480b311 100644
--- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/paragraph/CodeBlocks.kt
+++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/paragraph/CodeBlocks.kt
@@ -43,6 +43,15 @@ internal fun codeBlockOf(language: String?, lines: List): List.asCodeLinesOf(type: CodeBlock): List =
+ map { source ->
+ RichParagraph(type = CodeBlock(language = type.language, isBlockStart = false)).also { paragraph ->
+ paragraph.children.add(RichSpan(paragraph = paragraph, text = source.plainText()))
+ }
+ }
+
/** The style every character of this paragraph starts from. */
@OptIn(ExperimentalRichTextApi::class)
internal fun RichParagraph.baseSpanStyle(config: RichTextConfig): SpanStyle =
diff --git a/richeditor-compose/src/commonTest/kotlin/com/mohamedrejeb/richeditor/model/CodeBlockClipboardTest.kt b/richeditor-compose/src/commonTest/kotlin/com/mohamedrejeb/richeditor/model/CodeBlockClipboardTest.kt
new file mode 100644
index 00000000..61d89c58
--- /dev/null
+++ b/richeditor-compose/src/commonTest/kotlin/com/mohamedrejeb/richeditor/model/CodeBlockClipboardTest.kt
@@ -0,0 +1,199 @@
+package com.mohamedrejeb.richeditor.model
+
+import androidx.compose.foundation.text.input.toTextFieldBuffer
+import androidx.compose.ui.text.TextRange
+import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi
+import com.mohamedrejeb.richeditor.paragraph.codeBlockGroups
+import com.mohamedrejeb.richeditor.paragraph.plainText
+import com.mohamedrejeb.richeditor.paragraph.type.CodeBlock
+import kotlin.test.Test
+import kotlin.test.assertEquals
+import kotlin.test.assertTrue
+
+/**
+ * Selecting, copying, pasting and deleting around code blocks. What a selection exports is what
+ * a copy writes to the clipboard, and a paste goes through the same pipeline the editor uses.
+ *
+ * A code block is kept whole when it is pasted into ordinary text, and whatever is pasted into
+ * a code block becomes plain code lines of that block.
+ */
+@OptIn(ExperimentalRichTextApi::class)
+class CodeBlockClipboardTest {
+
+ private val markdown = "Before text\n\n```kotlin\nval a = 1\n val b = 2\nval c = 3\n```\n\nAfter text"
+ private val pythonBlockHtml = "p = 1\nq = 2
"
+
+ private fun state(source: String = markdown) = RichTextState().apply { setMarkdown(source) }
+
+ private fun RichTextState.offsetOf(text: String): Int = annotatedString.text.indexOf(text)
+
+ /** Each paragraph as `P:text` or `C:text`, with `C*` on the first line of a code block. */
+ private fun RichTextState.shape(): List = richParagraphList.map { paragraph ->
+ val type = paragraph.type as? CodeBlock
+ val mark = if (type == null) "P" else if (type.isBlockStart) "C*" else "C"
+ "$mark:${paragraph.plainText()}"
+ }
+
+ private fun RichTextState.paste(at: TextRange, plain: String, html: String? = null) {
+ selection = at
+ pendingClipboardHtml = html
+ pendingClipboardPlainText = plain
+ val buffer = textFieldState.toTextFieldBuffer()
+ buffer.replace(at.min, at.max, plain)
+ applyChangeList(buffer)
+ }
+
+ private fun RichTextState.delete(from: Int, to: Int) {
+ val buffer = textFieldState.toTextFieldBuffer()
+ buffer.replace(from, to, "")
+ applyChangeList(buffer)
+ }
+
+ @Test
+ fun `a whole block copies as code with its lines and indentation`() {
+ val state = state()
+ val range = TextRange(state.offsetOf("val a"), state.offsetOf("val c = 3") + 9)
+ assertEquals("val a = 1\n val b = 2\nval c = 3", state.toText(range))
+ assertEquals(
+ "val a = 1\n val b = 2\nval c = 3
",
+ state.toHtml(range),
+ )
+ assertEquals("```kotlin\nval a = 1\n val b = 2\nval c = 3\n```", state.toMarkdown(range))
+ }
+
+ @Test
+ fun `part of a block copies as a block of the selected text`() {
+ val state = state()
+ val range = TextRange(state.offsetOf("val a") + 4, state.offsetOf("val c") + 3)
+ assertEquals("a = 1\n val b = 2\nval", state.toText(range))
+ assertEquals("a = 1\n val b = 2\nval
", state.toHtml(range))
+ }
+
+ @Test
+ fun `a selection across text and code copies both`() {
+ val state = state()
+ val range = TextRange(state.offsetOf("text"), state.offsetOf("val b") + 5)
+ assertEquals("text\nval a = 1\n val b", state.toText(range))
+ assertEquals(
+ "text
val a = 1\n val b
",
+ state.toHtml(range),
+ )
+ assertEquals("text\n\n```kotlin\nval a = 1\n val b\n```", state.toMarkdown(range))
+ }
+
+ @Test
+ fun `plain lines pasted into a block become lines of that block`() {
+ val state = state()
+ state.paste(TextRange(state.offsetOf("val b")), "x = 1\ny = 2")
+ assertEquals(
+ listOf("P:Before text", "C*:val a = 1", "C: x = 1", "C:y = 2val b = 2", "C:val c = 3", "P:After text"),
+ state.shape(),
+ )
+ }
+
+ @Test
+ fun `a block pasted in the middle of text splits the text around it`() {
+ val state = state("Hello world")
+ state.paste(TextRange(5), "p = 1\nq = 2", pythonBlockHtml)
+ assertEquals(listOf("P:Hello", "C*:p = 1", "C:q = 2", "P: world"), state.shape())
+ assertEquals("Hello\n\n```python\np = 1\nq = 2\n```\n\n world", state.toMarkdown())
+ }
+
+ @Test
+ fun `a block pasted at the end of text follows it`() {
+ val state = state("Hello")
+ state.paste(TextRange(5), "p = 1\nq = 2", pythonBlockHtml)
+ assertEquals(listOf("P:Hello", "C*:p = 1", "C:q = 2"), state.shape())
+ }
+
+ @Test
+ fun `a block pasted at the start of text comes before it`() {
+ val state = state("Hello")
+ state.paste(TextRange(0), "p = 1\nq = 2", pythonBlockHtml)
+ assertEquals(listOf("C*:p = 1", "C:q = 2", "P:Hello"), state.shape())
+ }
+
+ @Test
+ fun `a block pasted next to another block stays a block of its own`() {
+ val state = state()
+ state.paste(TextRange(state.offsetOf("fore")), "p = 1\nq = 2", pythonBlockHtml)
+ assertEquals(
+ listOf("P:Be", "C*:p = 1", "C:q = 2", "P:fore text", "C*:val a = 1", "C: val b = 2", "C:val c = 3", "P:After text"),
+ state.shape(),
+ )
+ assertEquals(2, state.richParagraphList.toList().codeBlockGroups().size)
+ }
+
+ @Test
+ fun `one line of code pasted into text joins the text`() {
+ val state = state("Hello world")
+ state.paste(TextRange(5), "a = 1", "a = 1
")
+ assertEquals(listOf("P:Helloa = 1 world"), state.shape())
+ }
+
+ @Test
+ fun `part of a block copied from one editor pastes as a block into another`() {
+ val source = state()
+ val range = TextRange(source.offsetOf("val a") + 4, source.offsetOf("val c") + 3)
+ val target = state("Hello world")
+ target.paste(TextRange(5), source.toText(range), source.toHtml(range))
+ assertEquals(listOf("P:Hello", "C*:a = 1", "C: val b = 2", "C:val", "P: world"), target.shape())
+ }
+
+ @Test
+ fun `formatted text pasted into a block becomes plain code`() {
+ val state = state()
+ state.paste(TextRange(state.offsetOf("val b")), "bold", "bold")
+ assertEquals(
+ listOf("P:Before text", "C*:val a = 1", "C: boldval b = 2", "C:val c = 3", "P:After text"),
+ state.shape(),
+ )
+ assertTrue(state.toRichTextDocument().blocks[2].spans.isEmpty(), "no formatting inside the code line")
+ }
+
+ @Test
+ fun `paragraphs pasted into a block become lines of that block`() {
+ val state = state()
+ state.paste(TextRange(state.offsetOf("val b")), "x\ny\nz", "x
- y
z
")
+ assertEquals(
+ listOf("P:Before text", "C*:val a = 1", "C: x", "C:y", "C:zval b = 2", "C:val c = 3", "P:After text"),
+ state.shape(),
+ )
+ assertEquals(1, state.richParagraphList.toList().codeBlockGroups().size)
+ }
+
+ @Test
+ fun `a block pasted into a block joins it`() {
+ val state = state()
+ state.paste(TextRange(state.offsetOf("val b")), "p = 1\nq = 2", pythonBlockHtml)
+ assertEquals(
+ "Before text\n\n```kotlin\nval a = 1\n p = 1\nq = 2val b = 2\nval c = 3\n```\n\nAfter text",
+ state.toMarkdown(),
+ )
+ assertEquals(1, state.richParagraphList.toList().codeBlockGroups().size)
+ }
+
+ @Test
+ fun `deleting from text into a block keeps the rest of the block`() {
+ val state = state()
+ state.delete(state.offsetOf("text"), state.offsetOf("val b") + 5)
+ assertEquals(listOf("P:Before = 2", "C:val c = 3", "P:After text"), state.shape())
+ assertEquals("Before = 2\n\n```kotlin\nval c = 3\n```\n\nAfter text", state.toMarkdown())
+ assertEquals(1, state.renderedCodeBlocks.size)
+ }
+
+ @Test
+ fun `deleting the first line of a block keeps the block and its language`() {
+ val state = state()
+ state.delete(state.offsetOf("val a"), state.offsetOf(" val b"))
+ assertEquals("Before text\n\n```kotlin\n val b = 2\nval c = 3\n```\n\nAfter text", state.toMarkdown())
+ }
+
+ @Test
+ fun `deleting everything leaves an empty paragraph and no block`() {
+ val state = state()
+ state.delete(0, state.annotatedString.text.length)
+ assertEquals(listOf("P:"), state.shape())
+ assertEquals(emptyList(), state.renderedCodeBlocks)
+ }
+}
diff --git a/richeditor-compose/src/desktopTest/kotlin/com/mohamedrejeb/richeditor/clipboard/CodeBlockCopyTest.kt b/richeditor-compose/src/desktopTest/kotlin/com/mohamedrejeb/richeditor/clipboard/CodeBlockCopyTest.kt
new file mode 100644
index 00000000..972bc86e
--- /dev/null
+++ b/richeditor-compose/src/desktopTest/kotlin/com/mohamedrejeb/richeditor/clipboard/CodeBlockCopyTest.kt
@@ -0,0 +1,164 @@
+package com.mohamedrejeb.richeditor.clipboard
+
+import androidx.compose.foundation.layout.Box
+import androidx.compose.runtime.CompositionLocalProvider
+import androidx.compose.runtime.LaunchedEffect
+import androidx.compose.runtime.remember
+import androidx.compose.ui.ExperimentalComposeUiApi
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.focus.FocusRequester
+import androidx.compose.ui.focus.focusRequester
+import androidx.compose.ui.input.key.Key
+import androidx.compose.ui.platform.ClipEntry
+import androidx.compose.ui.platform.Clipboard
+import androidx.compose.ui.platform.LocalClipboard
+import androidx.compose.ui.platform.NativeClipboard
+import androidx.compose.ui.platform.testTag
+import androidx.compose.ui.test.DesktopComposeUiTest
+import androidx.compose.ui.test.ExperimentalTestApi
+import androidx.compose.ui.test.onNodeWithTag
+import androidx.compose.ui.test.performKeyInput
+import androidx.compose.ui.test.pressKey
+import androidx.compose.ui.test.runDesktopComposeUiTest
+import androidx.compose.ui.text.TextRange
+import com.mohamedrejeb.richeditor.model.RichTextState
+import com.mohamedrejeb.richeditor.ui.BasicRichTextEditor
+import java.awt.datatransfer.DataFlavor
+import kotlin.test.Test
+import kotlin.test.assertEquals
+import kotlin.test.assertNotNull
+import kotlin.test.assertTrue
+
+@OptIn(ExperimentalComposeUiApi::class)
+private class CodeBlockTestClipboard : Clipboard {
+ val awt = java.awt.datatransfer.Clipboard("test")
+
+ override val nativeClipboard: NativeClipboard get() = awt
+
+ override suspend fun getClipEntry(): ClipEntry? = null
+
+ override suspend fun setClipEntry(clipEntry: ClipEntry?) {
+ awt.setContents(clipEntry?.nativeClipEntry as? java.awt.datatransfer.Transferable, null)
+ }
+}
+
+/**
+ * Copy, cut and keyboard selection of code through the real editor: the clipboard gets the
+ * code line by line, with its indentation.
+ */
+@OptIn(ExperimentalTestApi::class)
+class CodeBlockCopyTest {
+
+ private val markdown = "Before\n\n```kotlin\nval a = 1\n val b = 2\n```\n\nAfter"
+
+ @Test
+ fun `copying a selection inside a block puts the code on the clipboard`() = runEditorTest { state, clipboard ->
+ val text = state.annotatedString.text
+ select(state, TextRange(text.indexOf("val a"), text.indexOf("val b = 2") + 9))
+
+ pressShortcut(Key.C)
+
+ assertEquals("val a = 1\n val b = 2", clipboard.plainText())
+ assertEquals(
+ "val a = 1\n val b = 2
",
+ clipboard.html(),
+ )
+ assertEquals(markdown, state.toMarkdown())
+ }
+
+ @Test
+ fun `copying across text and code puts both on the clipboard`() = runEditorTest { state, clipboard ->
+ select(state, TextRange(0, state.annotatedString.text.length))
+
+ pressShortcut(Key.C)
+
+ assertEquals("Before\nval a = 1\n val b = 2\nAfter", clipboard.plainText())
+ assertEquals(
+ "Before
val a = 1\n val b = 2
After
",
+ clipboard.html(),
+ )
+ }
+
+ @Test
+ fun `cutting a line of a block removes it and keeps the block`() = runEditorTest { state, clipboard ->
+ val text = state.annotatedString.text
+ select(state, TextRange(text.indexOf("val a"), text.indexOf("val b") - INDENT))
+
+ pressShortcut(Key.X)
+
+ assertEquals("val a = 1", clipboard.plainText())
+ assertEquals("Before\n\n```kotlin\n val b = 2\n```\n\nAfter", state.toMarkdown())
+ }
+
+ @Test
+ fun `keyboard selection extends across the lines of a block`() = runEditorTest { state, _ ->
+ val text = state.annotatedString.text
+ select(state, TextRange(text.indexOf("val a")))
+
+ onNodeWithTag(TAG).performKeyInput {
+ keyDown(Key.ShiftLeft)
+ pressKey(Key.DirectionDown)
+ keyUp(Key.ShiftLeft)
+ }
+ waitForIdle()
+
+ assertEquals(TextRange(text.indexOf("val a"), text.indexOf("val b") - INDENT), state.selection)
+ assertEquals("val a = 1", state.toText(state.selection))
+ }
+
+ private fun runEditorTest(
+ block: DesktopComposeUiTest.(state: RichTextState, clipboard: CodeBlockTestClipboard) -> Unit,
+ ) = runDesktopComposeUiTest {
+ val state = RichTextState().apply { setMarkdown(markdown) }
+ val clipboard = CodeBlockTestClipboard()
+ setContent {
+ val focusRequester = remember { FocusRequester() }
+ CompositionLocalProvider(LocalClipboard provides clipboard) {
+ Box {
+ BasicRichTextEditor(
+ state = state,
+ modifier = Modifier.focusRequester(focusRequester).testTag(TAG),
+ )
+ }
+ }
+ LaunchedEffect(Unit) { focusRequester.requestFocus() }
+ }
+ waitForIdle()
+ block(state, clipboard)
+ }
+
+ private fun DesktopComposeUiTest.select(state: RichTextState, range: TextRange) {
+ state.textFieldState.edit { selection = range }
+ waitForIdle()
+ }
+
+ private fun DesktopComposeUiTest.pressShortcut(key: Key) {
+ onNodeWithTag(TAG).performKeyInput {
+ keyDown(shortcutModifierKey)
+ pressKey(key)
+ keyUp(shortcutModifierKey)
+ }
+ waitForIdle()
+ }
+
+ private fun CodeBlockTestClipboard.plainText(): String {
+ val contents = assertNotNull(awt.getContents(null), "Expected clipboard contents")
+ assertTrue(contents.isDataFlavorSupported(DataFlavor.stringFlavor), "Expected plain text")
+ return contents.getTransferData(DataFlavor.stringFlavor) as String
+ }
+
+ private fun CodeBlockTestClipboard.html(): String {
+ val contents = assertNotNull(awt.getContents(null), "Expected clipboard contents")
+ assertTrue(contents.isDataFlavorSupported(DataFlavor.fragmentHtmlFlavor), "Expected html on the clipboard")
+ return contents.getTransferData(DataFlavor.fragmentHtmlFlavor) as String
+ }
+
+ private companion object {
+ const val TAG = "editor"
+ const val INDENT = 4
+
+ // The framework maps clipboard shortcuts to Meta on macOS and to Ctrl elsewhere.
+ val shortcutModifierKey: Key =
+ if (System.getProperty("os.name") == "Mac OS X") Key.MetaLeft else Key.CtrlLeft
+ }
+}
From 36530df3066d167eb25adc9a46eaf108a46ee5f0 Mon Sep 17 00:00:00 2001
From: MohamedRejeb
Date: Thu, 8 Oct 2026 23:31:08 +0100
Subject: [PATCH 13/16] fix: draw a cut off code block safely and leave typing
shortcuts out of code
---
docs/code_blocks.md | 21 ++++-
.../richeditor/model/CodeBlockRendering.kt | 9 +-
.../richeditor/model/TypingShortcuts.kt | 3 +
.../mohamedrejeb/richeditor/ui/ModifierExt.kt | 16 +++-
.../richeditor/model/CodeBlockTypingTest.kt | 55 ++++++++++++
.../richeditor/ui/BasicCodeTextTest.kt | 6 +-
.../richeditor/ui/CodeBlockRenderTest.kt | 89 +++++++++++++++++++
7 files changed, 192 insertions(+), 7 deletions(-)
create mode 100644 richeditor-compose/src/commonTest/kotlin/com/mohamedrejeb/richeditor/model/CodeBlockTypingTest.kt
diff --git a/docs/code_blocks.md b/docs/code_blocks.md
index 417ba268..e45e3769 100644
--- a/docs/code_blocks.md
+++ b/docs/code_blocks.md
@@ -68,6 +68,18 @@ The same block in each format:
The text inside a block is kept exactly as written: indentation, tabs, blank lines, and Markdown
or HTML that would otherwise be formatting.
+### Copy and paste
+
+Copying or cutting a selection that covers code writes the code line by line, with its
+indentation, as plain text and as a `` block in HTML.
+
+A code block pasted into ordinary text stays whole: the text is split around it. A single line
+of code pasted into a sentence joins the sentence as text. Whatever is pasted into a code block,
+formatted or not, becomes plain lines of that block.
+
+Typing shortcuts (`**bold**`, `__bold__`, `` `code` `` and the others) do nothing inside a code
+block, where those marks are code.
+
### Customizing
| Property on `RichTextState.config` | Type | Default | Description |
@@ -201,9 +213,14 @@ its language tag on export.
that was loaded can be edited, and Enter adds a line to it.
- Only fenced Markdown code is a code block. Code indented by four spaces is not.
- HTML, XML, CSS and diffs are not coloured yet.
-- Markup inside an HTML `` is read as plain code, so the colours of code copied from an IDE
- are replaced by the block's own.
+- Markup inside an HTML `` is read as plain code. Code copied from an IDE arrives as a
+ `` with coloured spans and no language, so it is pasted as a code block without colours.
- A code block inside a list item or a quote is moved to the top level.
+- A block has no space of its own above or below it, and two blocks in a row touch.
+- In Markdown, an empty paragraph directly after a block is not kept on a round trip.
+- Text selected in a read-only `RichText` inside a `SelectionContainer` is copied with a space
+ between paragraphs, so code selected that way loses its line ends. Copy and cut in the editors
+ keep them.
- `ExpandableBasicRichText` colours the code but draws no background behind it.
## Related
diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/model/CodeBlockRendering.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/model/CodeBlockRendering.kt
index b3e74ec3..1c5663c3 100644
--- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/model/CodeBlockRendering.kt
+++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/model/CodeBlockRendering.kt
@@ -12,9 +12,14 @@ import com.mohamedrejeb.richeditor.paragraph.RichParagraph
import com.mohamedrejeb.richeditor.paragraph.codeBlockGroups
import com.mohamedrejeb.richeditor.paragraph.type.CodeBlock
-/** A code block as it sits in the rendered text: where it is and the token styles drawn over it. */
+/**
+ * A code block as it sits in the rendered text: where it is and the token styles drawn over it.
+ * [lastLineOffset] is an offset on the last line of the block, which [range] cannot give: its
+ * end is the start of whatever follows, and an empty last line has no character of its own.
+ */
internal data class RenderedCodeBlock(
val range: TextRange,
+ val lastLineOffset: Int,
val styles: List>,
)
@@ -65,8 +70,10 @@ internal fun renderCodeBlocks(
if (separator in chars.indices && chars[separator] == ' ') chars[separator] = '\n'
}
val language = (paragraphs[group.first].type as? CodeBlock)?.language
+ val lastLine = ranges[group.last]
RenderedCodeBlock(
range = TextRange(start, end),
+ lastLineOffset = if (lastLine.start == lastLine.end) lastLine.start else lastLine.end - 1,
styles = cache.tokens(chars.concatToString(), language).map { token ->
AnnotatedString.Range(colors.styleOf(token.kind), start + token.start, start + token.end)
},
diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/model/TypingShortcuts.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/model/TypingShortcuts.kt
index a56d82d5..78b87b09 100644
--- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/model/TypingShortcuts.kt
+++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/model/TypingShortcuts.kt
@@ -8,6 +8,7 @@ import androidx.compose.ui.text.style.TextDecoration
import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi
import com.mohamedrejeb.richeditor.model.history.CommitTrigger
import com.mohamedrejeb.richeditor.paragraph.RichParagraph
+import com.mohamedrejeb.richeditor.paragraph.type.CodeBlock
import com.mohamedrejeb.richeditor.paragraph.type.DefaultParagraph
/** An inline Markdown mark and the formatting it stands for. Double marks come first so `**` wins over `*`. */
@@ -74,6 +75,8 @@ internal fun RichTextState.applyTypingShortcuts(inserted: String) {
if (at < 0 || !text.startsWith(inserted, at)) return
val (paragraph, paragraphRange) = paragraphAt(caret) ?: return
+ // Markdown marks are code inside a code block.
+ if (paragraph.type is CodeBlock) return
val contentStart = paragraphRange.min + paragraph.type.startRichSpan.text.length
if (caret <= contentStart) return
diff --git a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/ModifierExt.kt b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/ModifierExt.kt
index 467a6d4c..7a24787f 100644
--- a/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/ModifierExt.kt
+++ b/richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/ModifierExt.kt
@@ -43,10 +43,20 @@ internal fun Modifier.drawRichSpanStyle(
translate(top = -richTextState.scrollState.value.toFloat()) {
richTextState.textLayoutResult?.let { textLayoutResult ->
val textLength = textLayoutResult.layoutInput.text.length
- if (textLength > 0 && textLayoutResult.isForModelText(richTextState.annotatedString.length)) {
+ if (
+ textLength > 0 &&
+ textLayoutResult.lineCount > 0 &&
+ textLayoutResult.isForModelText(richTextState.annotatedString.length)
+ ) {
+ // maxLines and overflow stop the layout early, and asking it for a line
+ // past what it laid out throws.
+ val laidOutEnd = textLayoutResult.getLineEnd(textLayoutResult.lineCount - 1)
+ val isCutOff = laidOutEnd < textLength
+ val lastOffset = if (isCutOff) laidOutEnd - 1 else laidOutEnd
richTextState.renderedCodeBlocks.fastForEach { block ->
- val firstLine = textLayoutResult.getLineForOffset(block.range.min.coerceIn(0, textLength))
- val lastLine = textLayoutResult.getLineForOffset((block.range.max - 1).coerceIn(0, textLength))
+ if (block.range.min > lastOffset) return@fastForEach
+ val firstLine = textLayoutResult.getLineForOffset(block.range.min.coerceIn(0, lastOffset))
+ val lastLine = textLayoutResult.getLineForOffset(block.lastLineOffset.coerceIn(0, lastOffset))
val top = textLayoutResult.getLineTop(firstLine)
drawRoundRect(
color = richTextState.config.codeBlockBackgroundColor,
diff --git a/richeditor-compose/src/commonTest/kotlin/com/mohamedrejeb/richeditor/model/CodeBlockTypingTest.kt b/richeditor-compose/src/commonTest/kotlin/com/mohamedrejeb/richeditor/model/CodeBlockTypingTest.kt
new file mode 100644
index 00000000..e029f36e
--- /dev/null
+++ b/richeditor-compose/src/commonTest/kotlin/com/mohamedrejeb/richeditor/model/CodeBlockTypingTest.kt
@@ -0,0 +1,55 @@
+package com.mohamedrejeb.richeditor.model
+
+import androidx.compose.ui.text.TextRange
+import androidx.compose.ui.text.input.TextFieldValue
+import com.mohamedrejeb.richeditor.annotation.ExperimentalRichTextApi
+import kotlin.test.Test
+import kotlin.test.assertEquals
+
+/**
+ * Typing inside a code block: Markdown marks are code there, so the typing shortcuts that
+ * format ordinary text must leave them alone.
+ */
+@OptIn(ExperimentalRichTextApi::class)
+class CodeBlockTypingTest {
+
+ private fun codeState(): RichTextState = RichTextState().apply {
+ config.inlineTypingShortcutsEnabled = true
+ config.headingTypingShortcutsEnabled = true
+ setMarkdown("```python\nx\n```")
+ selection = TextRange(annotatedString.text.length)
+ }
+
+ /** Types [text] one character at a time at the caret, as a keyboard does. */
+ private fun RichTextState.type(text: String) {
+ text.forEach { char ->
+ val caret = selection.min
+ val current = annotatedString.text
+ val newText = current.substring(0, caret) + char + current.substring(caret)
+ onTextFieldValueChange(TextFieldValue(newText, TextRange(caret + 1)))
+ }
+ }
+
+ @Test
+ fun `underscores typed in a block stay as typed`() {
+ val state = codeState()
+ state.type(" = __init__")
+ assertEquals("```python\nx = __init__\n```", state.toMarkdown())
+ assertEquals(true, state.toRichTextDocument().blocks.single().spans.isEmpty())
+ }
+
+ @Test
+ fun `stars and backticks typed in a block stay as typed`() {
+ val state = codeState()
+ state.type(" = *a* + **b** + `c` + ~~d~~")
+ assertEquals("x = *a* + **b** + `c` + ~~d~~", state.annotatedString.text)
+ assertEquals(true, state.toRichTextDocument().blocks.single().spans.isEmpty())
+ }
+
+ @Test
+ fun `the same marks still format ordinary text`() {
+ val state = RichTextState().apply { config.inlineTypingShortcutsEnabled = true }
+ state.type("**bold**")
+ assertEquals("bold
", state.toHtml())
+ }
+}
diff --git a/richeditor-compose/src/desktopTest/kotlin/com/mohamedrejeb/richeditor/ui/BasicCodeTextTest.kt b/richeditor-compose/src/desktopTest/kotlin/com/mohamedrejeb/richeditor/ui/BasicCodeTextTest.kt
index 945ea93c..34228e45 100644
--- a/richeditor-compose/src/desktopTest/kotlin/com/mohamedrejeb/richeditor/ui/BasicCodeTextTest.kt
+++ b/richeditor-compose/src/desktopTest/kotlin/com/mohamedrejeb/richeditor/ui/BasicCodeTextTest.kt
@@ -50,7 +50,11 @@ class BasicCodeTextTest {
}
waitForIdle()
- assertEquals(1, assertNotNull(layout).lineCount)
+ val result = assertNotNull(layout)
+ assertEquals(1, result.lineCount)
+ // Laid out wider than the 120.dp parent and not clipped: the line scrolls sideways.
+ assertTrue(result.size.width > 120, "the line keeps its full width, was ${result.size.width}")
+ assertTrue(!result.didOverflowWidth, "the line is not cut off")
}
@Test
diff --git a/richeditor-compose/src/desktopTest/kotlin/com/mohamedrejeb/richeditor/ui/CodeBlockRenderTest.kt b/richeditor-compose/src/desktopTest/kotlin/com/mohamedrejeb/richeditor/ui/CodeBlockRenderTest.kt
index 74ed7ad2..6df4d8bf 100644
--- a/richeditor-compose/src/desktopTest/kotlin/com/mohamedrejeb/richeditor/ui/CodeBlockRenderTest.kt
+++ b/richeditor-compose/src/desktopTest/kotlin/com/mohamedrejeb/richeditor/ui/CodeBlockRenderTest.kt
@@ -9,6 +9,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.graphics.PixelMap
import androidx.compose.ui.graphics.toPixelMap
import androidx.compose.ui.input.key.Key
import androidx.compose.ui.platform.testTag
@@ -133,6 +134,94 @@ class CodeBlockRenderTest {
assertTrue(!isRedAtLine(0), "the plain line has no block background")
}
+ @Test
+ fun `a block cut off by maxLines is drawn without crashing`() = runDesktopComposeUiTest {
+ val state = RichTextState().apply {
+ config.codeBlockBackgroundColor = Color.Red
+ setMarkdown("```\none\ntwo\nthree\n```")
+ }
+ var layout: TextLayoutResult? = null
+ setContent {
+ Box(Modifier.width(200.dp)) {
+ BasicRichText(
+ state = state,
+ modifier = Modifier.testTag(EDITOR_TAG).fillMaxWidth(),
+ maxLines = 2,
+ onTextLayout = { layout = it },
+ )
+ }
+ }
+ waitForIdle()
+
+ val lines = assertNotNull(layout)
+ assertEquals(2, lines.lineCount)
+ val pixels = onNodeWithTag(EDITOR_TAG).captureToImage().toPixelMap()
+ assertTrue(pixels.isRedAt(pixels.width - 12, lines.lineMiddle(0)), "the first visible line has the background")
+ assertTrue(pixels.isRedAt(pixels.width - 12, lines.lineMiddle(1)), "the last visible line has the background")
+ }
+
+ @Test
+ fun `a block that lies past maxLines is skipped without crashing`() = runDesktopComposeUiTest {
+ val state = RichTextState().apply {
+ config.codeBlockBackgroundColor = Color.Red
+ setMarkdown("text\n\n```\ncode\n```")
+ }
+ var layout: TextLayoutResult? = null
+ setContent {
+ Box(Modifier.width(200.dp)) {
+ BasicRichText(
+ state = state,
+ modifier = Modifier.testTag(EDITOR_TAG).fillMaxWidth(),
+ maxLines = 1,
+ onTextLayout = { layout = it },
+ )
+ }
+ }
+ waitForIdle()
+
+ val lines = assertNotNull(layout)
+ assertEquals(1, lines.lineCount)
+ val pixels = onNodeWithTag(EDITOR_TAG).captureToImage().toPixelMap()
+ assertTrue(!pixels.isRedAt(pixels.width - 12, lines.lineMiddle(0)), "the plain line has no background")
+ }
+
+ @Test
+ fun `an empty last line of a block has the background`() = runDesktopComposeUiTest {
+ val state = RichTextState().apply {
+ config.codeBlockBackgroundColor = Color.Red
+ setMarkdown("```\ncode\n```")
+ }
+ setContent {
+ val focusRequester = remember { FocusRequester() }
+ Box(Modifier.width(200.dp)) {
+ BasicRichTextEditor(
+ state = state,
+ modifier = Modifier.focusRequester(focusRequester).testTag(EDITOR_TAG).fillMaxWidth(),
+ )
+ }
+ LaunchedEffect(Unit) { focusRequester.requestFocus() }
+ }
+ waitForIdle()
+ state.textFieldState.edit { selection = TextRange(length) }
+ waitForIdle()
+
+ onNodeWithTag(EDITOR_TAG).performKeyInput { pressKey(Key.Enter) }
+ waitForIdle()
+
+ val lines = editorLayout(state)
+ assertEquals(2, lines.lineCount)
+ val pixels = onNodeWithTag(EDITOR_TAG).captureToImage().toPixelMap()
+ assertTrue(pixels.isRedAt(pixels.width - 12, lines.lineMiddle(0)), "the code line has the background")
+ assertTrue(pixels.isRedAt(pixels.width - 12, lines.lineMiddle(1)), "the new empty line has the background")
+ }
+
+ private fun TextLayoutResult.lineMiddle(line: Int): Int = ((getLineTop(line) + getLineBottom(line)) / 2).toInt()
+
+ private fun PixelMap.isRedAt(x: Int, y: Int): Boolean {
+ val color = this[x, y]
+ return color.red > 0.8f && color.green < 0.3f && color.blue < 0.3f
+ }
+
private fun runEditorTest(block: DesktopComposeUiTest.(state: RichTextState) -> Unit) = runDesktopComposeUiTest {
val state = RichTextState().apply { setMarkdown(markdown) }
setContent {
From 3eeb1bf057ccb53725bebb5bc78405088f5f06fe Mon Sep 17 00:00:00 2001
From: MohamedRejeb
Date: Thu, 8 Oct 2026 23:43:52 +0100
Subject: [PATCH 14/16] feat: add a copy button and an action slot on code
blocks in RichText
---
docs/code_blocks.md | 31 +++
.../api/desktop/richeditor-compose.api | 6 +-
.../api/richeditor-compose.klib.api | 12 +-
.../richeditor/model/CodeBlockRendering.kt | 20 ++
.../richeditor/ui/BasicRichText.kt | 151 +++++++-------
.../richeditor/ui/CodeBlockActionLayout.kt | 60 ++++++
.../richeditor/ui/CodeBlockCopyButton.kt | 63 ++++++
.../mohamedrejeb/richeditor/ui/ModifierExt.kt | 21 +-
.../richeditor/ui/material/RichText.kt | 7 +
.../richeditor/ui/material3/RichText.kt | 7 +
.../richeditor/ui/CodeBlockActionTest.kt | 185 ++++++++++++++++++
.../codeblocks/CodeBlocksSampleScreen.kt | 4 +-
12 files changed, 466 insertions(+), 101 deletions(-)
create mode 100644 richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/CodeBlockActionLayout.kt
create mode 100644 richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/ui/CodeBlockCopyButton.kt
create mode 100644 richeditor-compose/src/desktopTest/kotlin/com/mohamedrejeb/richeditor/ui/CodeBlockActionTest.kt
diff --git a/docs/code_blocks.md b/docs/code_blocks.md
index e45e3769..43c7472a 100644
--- a/docs/code_blocks.md
+++ b/docs/code_blocks.md
@@ -80,6 +80,37 @@ formatted or not, becomes plain lines of that block.
Typing shortcuts (`**bold**`, `__bold__`, `` `code` `` and the others) do nothing inside a code
block, where those marks are code.
+### Copy button
+
+A read-only `RichText` can show a copy button at the top end corner of each code block. It copies
+the block's code exactly, line ends and indentation included:
+
+```kotlin
+RichText(
+ state = state,
+ modifier = Modifier.fillMaxWidth(),
+ showCodeBlockCopyButton = true,
+)
+```
+
+The Material and Material3 `RichText` both have the option, and it is off by default. For a
+button of your own, or any other action, `BasicRichText` takes a slot that is given the code and
+the language of each block:
+
+```kotlin
+BasicRichText(
+ state = state,
+ modifier = Modifier.fillMaxWidth(),
+ codeBlockAction = { code, language ->
+ MyCopyButton(onClick = { copyToClipboard(code) })
+ },
+)
+```
+
+The action is drawn over the corner of the block and takes no room of its own, so keep it about
+one line tall: on a block with a long first line it covers the end of that line. The editors do
+not have this option.
+
### Customizing
| Property on `RichTextState.config` | Type | Default | Description |
diff --git a/richeditor-compose/api/desktop/richeditor-compose.api b/richeditor-compose/api/desktop/richeditor-compose.api
index 424adbc5..501e238c 100644
--- a/richeditor-compose/api/desktop/richeditor-compose.api
+++ b/richeditor-compose/api/desktop/richeditor-compose.api
@@ -1020,7 +1020,7 @@ public final class com/mohamedrejeb/richeditor/ui/BasicRichTextEditorKt {
}
public final class com/mohamedrejeb/richeditor/ui/BasicRichTextKt {
- public static final fun BasicRichText-Jzo1Dmk (Lcom/mohamedrejeb/richeditor/model/RichTextState;Landroidx/compose/ui/Modifier;Landroidx/compose/ui/text/TextStyle;Lkotlin/jvm/functions/Function1;IZIILjava/util/Map;Lcom/mohamedrejeb/richeditor/model/ImageLoader;Lcom/mohamedrejeb/richeditor/model/TokenClickHandler;Lcom/mohamedrejeb/richeditor/model/TokenHoverHandler;Landroidx/compose/runtime/Composer;III)V
+ public static final fun BasicRichText-Kj_y3YE (Lcom/mohamedrejeb/richeditor/model/RichTextState;Landroidx/compose/ui/Modifier;Landroidx/compose/ui/text/TextStyle;Lkotlin/jvm/functions/Function1;IZIILjava/util/Map;Lcom/mohamedrejeb/richeditor/model/ImageLoader;Lcom/mohamedrejeb/richeditor/model/TokenClickHandler;Lcom/mohamedrejeb/richeditor/model/TokenHoverHandler;Lkotlin/jvm/functions/Function4;Landroidx/compose/runtime/Composer;III)V
}
public final class com/mohamedrejeb/richeditor/ui/ComposableSingletons$BasicRichTextEditorKt {
@@ -1051,7 +1051,7 @@ public final class com/mohamedrejeb/richeditor/ui/material/RichTextEditorKt {
}
public final class com/mohamedrejeb/richeditor/ui/material/RichTextKt {
- public static final fun RichText-mQfddtU (Lcom/mohamedrejeb/richeditor/model/RichTextState;Landroidx/compose/ui/Modifier;JJLandroidx/compose/ui/text/font/FontStyle;Landroidx/compose/ui/text/font/FontWeight;Landroidx/compose/ui/text/font/FontFamily;JLandroidx/compose/ui/text/style/TextDecoration;IJIZIILjava/util/Map;Lkotlin/jvm/functions/Function1;Landroidx/compose/ui/text/TextStyle;Lcom/mohamedrejeb/richeditor/model/ImageLoader;Lcom/mohamedrejeb/richeditor/model/TokenClickHandler;Lcom/mohamedrejeb/richeditor/model/TokenHoverHandler;Landroidx/compose/runtime/Composer;IIII)V
+ public static final fun RichText-KrekslA (Lcom/mohamedrejeb/richeditor/model/RichTextState;Landroidx/compose/ui/Modifier;JJLandroidx/compose/ui/text/font/FontStyle;Landroidx/compose/ui/text/font/FontWeight;Landroidx/compose/ui/text/font/FontFamily;JLandroidx/compose/ui/text/style/TextDecoration;IJIZIILjava/util/Map;Lkotlin/jvm/functions/Function1;Landroidx/compose/ui/text/TextStyle;Lcom/mohamedrejeb/richeditor/model/ImageLoader;Lcom/mohamedrejeb/richeditor/model/TokenClickHandler;Lcom/mohamedrejeb/richeditor/model/TokenHoverHandler;ZLandroidx/compose/runtime/Composer;IIII)V
}
public final class com/mohamedrejeb/richeditor/ui/material3/ExpandableRichTextKt {
@@ -1100,7 +1100,7 @@ public final class com/mohamedrejeb/richeditor/ui/material3/RichTextEditorKt {
}
public final class com/mohamedrejeb/richeditor/ui/material3/RichTextKt {
- public static final fun RichText-mQfddtU (Lcom/mohamedrejeb/richeditor/model/RichTextState;Landroidx/compose/ui/Modifier;JJLandroidx/compose/ui/text/font/FontStyle;Landroidx/compose/ui/text/font/FontWeight;Landroidx/compose/ui/text/font/FontFamily;JLandroidx/compose/ui/text/style/TextDecoration;IJIZIILjava/util/Map;Lkotlin/jvm/functions/Function1;Landroidx/compose/ui/text/TextStyle;Lcom/mohamedrejeb/richeditor/model/ImageLoader;Lcom/mohamedrejeb/richeditor/model/TokenClickHandler;Lcom/mohamedrejeb/richeditor/model/TokenHoverHandler;Landroidx/compose/runtime/Composer;IIII)V
+ public static final fun RichText-KrekslA (Lcom/mohamedrejeb/richeditor/model/RichTextState;Landroidx/compose/ui/Modifier;JJLandroidx/compose/ui/text/font/FontStyle;Landroidx/compose/ui/text/font/FontWeight;Landroidx/compose/ui/text/font/FontFamily;JLandroidx/compose/ui/text/style/TextDecoration;IJIZIILjava/util/Map;Lkotlin/jvm/functions/Function1;Landroidx/compose/ui/text/TextStyle;Lcom/mohamedrejeb/richeditor/model/ImageLoader;Lcom/mohamedrejeb/richeditor/model/TokenClickHandler;Lcom/mohamedrejeb/richeditor/model/TokenHoverHandler;ZLandroidx/compose/runtime/Composer;IIII)V
}
public final class com/mohamedrejeb/richeditor/ui/material3/TriggerSuggestionsKt {
diff --git a/richeditor-compose/api/richeditor-compose.klib.api b/richeditor-compose/api/richeditor-compose.klib.api
index db20d4a3..86671369 100644
--- a/richeditor-compose/api/richeditor-compose.klib.api
+++ b/richeditor-compose/api/richeditor-compose.klib.api
@@ -1320,19 +1320,19 @@ final fun com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor
final fun com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor_paragraph_type_UnorderedListStyleType$stableprop_getter(): kotlin/Int // com.mohamedrejeb.richeditor.paragraph.type/com_mohamedrejeb_richeditor_paragraph_type_UnorderedListStyleType$stableprop_getter|com_mohamedrejeb_richeditor_paragraph_type_UnorderedListStyleType$stableprop_getter(){}[0]
final fun com.mohamedrejeb.richeditor.parser.html/com_mohamedrejeb_richeditor_parser_html_CssDecoder_HtmlStylingFormat$stableprop_getter(): kotlin/Int // com.mohamedrejeb.richeditor.parser.html/com_mohamedrejeb_richeditor_parser_html_CssDecoder_HtmlStylingFormat$stableprop_getter|com_mohamedrejeb_richeditor_parser_html_CssDecoder_HtmlStylingFormat$stableprop_getter(){}[0]
final fun com.mohamedrejeb.richeditor.ui.material/OutlinedRichTextEditor(com.mohamedrejeb.richeditor.model/RichTextState, androidx.compose.ui/Modifier?, kotlin/Boolean, kotlin/Boolean, androidx.compose.ui.text/TextStyle?, kotlin/Function2?, kotlin/Function2?, kotlin/Function2?, kotlin/Function2?, kotlin/Boolean, androidx.compose.foundation.text/KeyboardOptions?, androidx.compose.foundation.text/KeyboardActions?, kotlin/Boolean, kotlin/Int, kotlin/Int, kotlin/Int, androidx.compose.foundation.interaction/MutableInteractionSource?, androidx.compose.ui.graphics/Shape?, androidx.compose.material/TextFieldColors?, com.mohamedrejeb.richeditor.ui/UndoBehavior?, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int, kotlin/Int) // com.mohamedrejeb.richeditor.ui.material/OutlinedRichTextEditor|OutlinedRichTextEditor(com.mohamedrejeb.richeditor.model.RichTextState;androidx.compose.ui.Modifier?;kotlin.Boolean;kotlin.Boolean;androidx.compose.ui.text.TextStyle?;kotlin.Function2?;kotlin.Function2?;kotlin.Function2?;kotlin.Function2?;kotlin.Boolean;androidx.compose.foundation.text.KeyboardOptions?;androidx.compose.foundation.text.KeyboardActions?;kotlin.Boolean;kotlin.Int;kotlin.Int;kotlin.Int;androidx.compose.foundation.interaction.MutableInteractionSource?;androidx.compose.ui.graphics.Shape?;androidx.compose.material.TextFieldColors?;com.mohamedrejeb.richeditor.ui.UndoBehavior?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int;kotlin.Int){}[0]
-final fun com.mohamedrejeb.richeditor.ui.material/RichText(com.mohamedrejeb.richeditor.model/RichTextState, androidx.compose.ui/Modifier?, androidx.compose.ui.graphics/Color, androidx.compose.ui.unit/TextUnit, androidx.compose.ui.text.font/FontStyle?, androidx.compose.ui.text.font/FontWeight?, androidx.compose.ui.text.font/FontFamily?, androidx.compose.ui.unit/TextUnit, androidx.compose.ui.text.style/TextDecoration?, androidx.compose.ui.text.style/TextAlign, androidx.compose.ui.unit/TextUnit, androidx.compose.ui.text.style/TextOverflow, kotlin/Boolean, kotlin/Int, kotlin/Int, kotlin.collections/Map?, kotlin/Function1?, androidx.compose.ui.text/TextStyle?, com.mohamedrejeb.richeditor.model/ImageLoader?, com.mohamedrejeb.richeditor.model/TokenClickHandler?, com.mohamedrejeb.richeditor.model/TokenHoverHandler?, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int, kotlin/Int, kotlin/Int) // com.mohamedrejeb.richeditor.ui.material/RichText|RichText(com.mohamedrejeb.richeditor.model.RichTextState;androidx.compose.ui.Modifier?;androidx.compose.ui.graphics.Color;androidx.compose.ui.unit.TextUnit;androidx.compose.ui.text.font.FontStyle?;androidx.compose.ui.text.font.FontWeight?;androidx.compose.ui.text.font.FontFamily?;androidx.compose.ui.unit.TextUnit;androidx.compose.ui.text.style.TextDecoration?;androidx.compose.ui.text.style.TextAlign;androidx.compose.ui.unit.TextUnit;androidx.compose.ui.text.style.TextOverflow;kotlin.Boolean;kotlin.Int;kotlin.Int;kotlin.collections.Map?;kotlin.Function1?;androidx.compose.ui.text.TextStyle?;com.mohamedrejeb.richeditor.model.ImageLoader?;com.mohamedrejeb.richeditor.model.TokenClickHandler?;com.mohamedrejeb.richeditor.model.TokenHoverHandler?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int;kotlin.Int;kotlin.Int){}[0]
-final fun com.mohamedrejeb.richeditor.ui.material/RichText(com.mohamedrejeb.richeditor.model/RichTextState, androidx.compose.ui/Modifier?, androidx.compose.ui.graphics/Color, androidx.compose.ui.unit/TextUnit?, androidx.compose.ui.text.font/FontStyle?, androidx.compose.ui.text.font/FontWeight?, androidx.compose.ui.text.font/FontFamily?, androidx.compose.ui.unit/TextUnit?, androidx.compose.ui.text.style/TextDecoration?, androidx.compose.ui.text.style/TextAlign?, androidx.compose.ui.unit/TextUnit?, androidx.compose.ui.text.style/TextOverflow?, kotlin/Boolean, kotlin/Int, kotlin/Int, kotlin.collections/Map?, kotlin/Function1?, androidx.compose.ui.text/TextStyle?, com.mohamedrejeb.richeditor.model/ImageLoader?, com.mohamedrejeb.richeditor.model/TokenClickHandler?, com.mohamedrejeb.richeditor.model/TokenHoverHandler?, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int, kotlin/Int, kotlin/Int) // com.mohamedrejeb.richeditor.ui.material/RichText|RichText(com.mohamedrejeb.richeditor.model.RichTextState;androidx.compose.ui.Modifier?;androidx.compose.ui.graphics.Color;androidx.compose.ui.unit.TextUnit?;androidx.compose.ui.text.font.FontStyle?;androidx.compose.ui.text.font.FontWeight?;androidx.compose.ui.text.font.FontFamily?;androidx.compose.ui.unit.TextUnit?;androidx.compose.ui.text.style.TextDecoration?;androidx.compose.ui.text.style.TextAlign?;androidx.compose.ui.unit.TextUnit?;androidx.compose.ui.text.style.TextOverflow?;kotlin.Boolean;kotlin.Int;kotlin.Int;kotlin.collections.Map?;kotlin.Function1?;androidx.compose.ui.text.TextStyle?;com.mohamedrejeb.richeditor.model.ImageLoader?;com.mohamedrejeb.richeditor.model.TokenClickHandler?;com.mohamedrejeb.richeditor.model.TokenHoverHandler?;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int;kotlin.Int;kotlin.Int){}[0]
+final fun com.mohamedrejeb.richeditor.ui.material/RichText(com.mohamedrejeb.richeditor.model/RichTextState, androidx.compose.ui/Modifier?, androidx.compose.ui.graphics/Color, androidx.compose.ui.unit/TextUnit, androidx.compose.ui.text.font/FontStyle?, androidx.compose.ui.text.font/FontWeight?, androidx.compose.ui.text.font/FontFamily?, androidx.compose.ui.unit/TextUnit, androidx.compose.ui.text.style/TextDecoration?, androidx.compose.ui.text.style/TextAlign, androidx.compose.ui.unit/TextUnit, androidx.compose.ui.text.style/TextOverflow, kotlin/Boolean, kotlin/Int, kotlin/Int, kotlin.collections/Map?, kotlin/Function1?, androidx.compose.ui.text/TextStyle?, com.mohamedrejeb.richeditor.model/ImageLoader?, com.mohamedrejeb.richeditor.model/TokenClickHandler?, com.mohamedrejeb.richeditor.model/TokenHoverHandler?, kotlin/Boolean, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int, kotlin/Int, kotlin/Int) // com.mohamedrejeb.richeditor.ui.material/RichText|RichText(com.mohamedrejeb.richeditor.model.RichTextState;androidx.compose.ui.Modifier?;androidx.compose.ui.graphics.Color;androidx.compose.ui.unit.TextUnit;androidx.compose.ui.text.font.FontStyle?;androidx.compose.ui.text.font.FontWeight?;androidx.compose.ui.text.font.FontFamily?;androidx.compose.ui.unit.TextUnit;androidx.compose.ui.text.style.TextDecoration?;androidx.compose.ui.text.style.TextAlign;androidx.compose.ui.unit.TextUnit;androidx.compose.ui.text.style.TextOverflow;kotlin.Boolean;kotlin.Int;kotlin.Int;kotlin.collections.Map?;kotlin.Function1?;androidx.compose.ui.text.TextStyle?;com.mohamedrejeb.richeditor.model.ImageLoader?;com.mohamedrejeb.richeditor.model.TokenClickHandler?;com.mohamedrejeb.richeditor.model.TokenHoverHandler?;kotlin.Boolean;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int;kotlin.Int;kotlin.Int){}[0]
+final fun com.mohamedrejeb.richeditor.ui.material/RichText(com.mohamedrejeb.richeditor.model/RichTextState, androidx.compose.ui/Modifier?, androidx.compose.ui.graphics/Color, androidx.compose.ui.unit/TextUnit?, androidx.compose.ui.text.font/FontStyle?, androidx.compose.ui.text.font/FontWeight?, androidx.compose.ui.text.font/FontFamily?, androidx.compose.ui.unit/TextUnit?, androidx.compose.ui.text.style/TextDecoration?, androidx.compose.ui.text.style/TextAlign?, androidx.compose.ui.unit/TextUnit?, androidx.compose.ui.text.style/TextOverflow?, kotlin/Boolean, kotlin/Int, kotlin/Int, kotlin.collections/Map?, kotlin/Function1?, androidx.compose.ui.text/TextStyle?, com.mohamedrejeb.richeditor.model/ImageLoader?, com.mohamedrejeb.richeditor.model/TokenClickHandler?, com.mohamedrejeb.richeditor.model/TokenHoverHandler?, kotlin/Boolean, androidx.compose.runtime/Composer?, kotlin/Int, kotlin/Int, kotlin/Int, kotlin/Int) // com.mohamedrejeb.richeditor.ui.material/RichText|RichText(com.mohamedrejeb.richeditor.model.RichTextState;androidx.compose.ui.Modifier?;androidx.compose.ui.graphics.Color;androidx.compose.ui.unit.TextUnit?;androidx.compose.ui.text.font.FontStyle?;androidx.compose.ui.text.font.FontWeight?;androidx.compose.ui.text.font.FontFamily?;androidx.compose.ui.unit.TextUnit?;androidx.compose.ui.text.style.TextDecoration?;androidx.compose.ui.text.style.TextAlign?;androidx.compose.ui.unit.TextUnit?;androidx.compose.ui.text.style.TextOverflow?;kotlin.Boolean;kotlin.Int;kotlin.Int;kotlin.collections.Map?;kotlin.Function1?;androidx.compose.ui.text.TextStyle?;com.mohamedrejeb.richeditor.model.ImageLoader?;com.mohamedrejeb.richeditor.model.TokenClickHandler?;com.mohamedrejeb.richeditor.model.TokenHoverHandler?;kotlin.Boolean;androidx.compose.runtime.Composer?;kotlin.Int;kotlin.Int;kotlin.Int;kotlin.Int){}[0]
final fun com.mohamedrejeb.richeditor.ui.material/RichTextEditor(com.mohamedrejeb.richeditor.model/RichTextState, androidx.compose.ui/Modifier?, kotlin/Boolean, kotlin/Boolean, androidx.compose.ui.text/TextStyle?, kotlin/Function2?, kotlin/Function2?, kotlin/Function2?, kotlin/Function2