From c99133e90fb2d42143c2a852e1336f5bcaf5dba3 Mon Sep 17 00:00:00 2001 From: MohamedRejeb Date: Sun, 10 Nov 2024 13:53:51 +0100 Subject: [PATCH 1/5] Fix auto-detect ordered list start takes only the first digit --- .../richeditor/model/RichTextState.kt | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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 732597c9..0800ec05 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 @@ -1622,12 +1622,15 @@ public class RichTextState internal constructor( ) richSpan.text = "" } else if (richSpan.text.matches(Regex("^\\d+\\. "))) { - val number = richSpan.text.first().digitToIntOrNull() ?: 1 - richSpan.paragraph.type = OrderedList( - number = number, - initialIndent = config.orderedListIndent, - ) - richSpan.text = "" + val dotIndex = richSpan.text.indexOf('.') + if (dotIndex != -1) { + val number = richSpan.text.substring(0, dotIndex).toIntOrNull() ?: 1 + richSpan.paragraph.type = OrderedList( + number = number, + initialIndent = config.orderedListIndent, + ) + richSpan.text = "" + } } } From 8af15bc04ca0327fced735fde53cdd38a30fda6a Mon Sep 17 00:00:00 2001 From: MohamedRejeb Date: Sun, 10 Nov 2024 14:03:39 +0100 Subject: [PATCH 2/5] Add tests --- .../model/RichTextStateTest.kt | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/richeditor-compose/src/commonTest/kotlin/com.mohamedrejeb.richeditor/model/RichTextStateTest.kt b/richeditor-compose/src/commonTest/kotlin/com.mohamedrejeb.richeditor/model/RichTextStateTest.kt index 95e1da03..bcc6b5d9 100644 --- a/richeditor-compose/src/commonTest/kotlin/com.mohamedrejeb.richeditor/model/RichTextStateTest.kt +++ b/richeditor-compose/src/commonTest/kotlin/com.mohamedrejeb.richeditor/model/RichTextStateTest.kt @@ -1196,4 +1196,45 @@ class RichTextStateTest { assertEquals(2, richTextState.richParagraphList.size) } + fun testAutoRecognizeOrderedListUtil(number: Int) { + val state = RichTextState() + val text = "$number. " + + state.onTextFieldValueChange( + TextFieldValue( + text = text, + selection = TextRange(text.length), + ) + ) + + val orderedList = state.richParagraphList.first().type + + assertIs(orderedList) + assertEquals(number, orderedList.number) + assertTrue(state.isOrderedList) + } + + @Test + fun testAutoRecognizeOrderedList() { + testAutoRecognizeOrderedListUtil(1) + testAutoRecognizeOrderedListUtil(28) + } + + @Test + fun testAutoRecognizeUnorderedList() { + val state = RichTextState() + + state.onTextFieldValueChange( + TextFieldValue( + text = "- ", + selection = TextRange(2), + ) + ) + + val orderedList = state.richParagraphList.first().type + + assertIs(orderedList) + assertTrue(state.isUnorderedList) + } + } \ No newline at end of file From d873ffb0afb18501c9cf0a59b4c3f7c973bcba10 Mon Sep 17 00:00:00 2001 From: MohamedRejeb Date: Sun, 10 Nov 2024 14:04:37 +0100 Subject: [PATCH 3/5] Remove prints --- .../parser/markdown/RichTextStateMarkdownParserDecodeTest.kt | 2 -- .../parser/markdown/RichTextStateMarkdownParserEncodeTest.kt | 2 -- 2 files changed, 4 deletions(-) diff --git a/richeditor-compose/src/commonTest/kotlin/com.mohamedrejeb.richeditor/parser/markdown/RichTextStateMarkdownParserDecodeTest.kt b/richeditor-compose/src/commonTest/kotlin/com.mohamedrejeb.richeditor/parser/markdown/RichTextStateMarkdownParserDecodeTest.kt index ac742691..0c59b015 100644 --- a/richeditor-compose/src/commonTest/kotlin/com.mohamedrejeb.richeditor/parser/markdown/RichTextStateMarkdownParserDecodeTest.kt +++ b/richeditor-compose/src/commonTest/kotlin/com.mohamedrejeb.richeditor/parser/markdown/RichTextStateMarkdownParserDecodeTest.kt @@ -366,8 +366,6 @@ class RichTextStateMarkdownParserDecodeTest { state.setMarkdown(markdown) - state.printParagraphs() - assertEquals( """ # Prompt diff --git a/richeditor-compose/src/commonTest/kotlin/com.mohamedrejeb.richeditor/parser/markdown/RichTextStateMarkdownParserEncodeTest.kt b/richeditor-compose/src/commonTest/kotlin/com.mohamedrejeb.richeditor/parser/markdown/RichTextStateMarkdownParserEncodeTest.kt index 38d84f35..e5d50242 100644 --- a/richeditor-compose/src/commonTest/kotlin/com.mohamedrejeb.richeditor/parser/markdown/RichTextStateMarkdownParserEncodeTest.kt +++ b/richeditor-compose/src/commonTest/kotlin/com.mohamedrejeb.richeditor/parser/markdown/RichTextStateMarkdownParserEncodeTest.kt @@ -415,8 +415,6 @@ class RichTextStateMarkdownParserEncodeTest { state.setMarkdown(markdown) - state.printParagraphs() - assertEquals(2, state.richParagraphList.size) val firstParagraph = state.richParagraphList[0] From 918601fb83475966baca35815eb7641da831a05e Mon Sep 17 00:00:00 2001 From: MohamedRejeb Date: Sun, 10 Nov 2024 14:12:18 +0100 Subject: [PATCH 4/5] Remove unnecessary code --- .../richeditor/sample/common/slack/SlackDemoContent.kt | 7 ------- .../richeditor/sample/common/slack/SlackDemoPanelButton.kt | 7 ------- 2 files changed, 14 deletions(-) diff --git a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/slack/SlackDemoContent.kt b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/slack/SlackDemoContent.kt index dddec860..7c2aacb4 100644 --- a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/slack/SlackDemoContent.kt +++ b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/slack/SlackDemoContent.kt @@ -4,7 +4,6 @@ import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.clickable -import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.* import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.items @@ -12,9 +11,6 @@ import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.filled.ArrowBack import androidx.compose.material.icons.automirrored.outlined.Send -import androidx.compose.material.icons.filled.ArrowBack -import androidx.compose.material.icons.outlined.Send -import androidx.compose.material.ripple.rememberRipple import androidx.compose.material3.* import androidx.compose.runtime.* import androidx.compose.ui.Alignment @@ -188,7 +184,6 @@ fun SlackDemoContent() { .padding(8.dp) ) - // 1d99ce Box( modifier = Modifier .padding(8.dp) @@ -201,8 +196,6 @@ fun SlackDemoContent() { }, enabled = true, role = Role.Button, - interactionSource = remember { MutableInteractionSource() }, - indication = rememberRipple() ), contentAlignment = Alignment.Center ) { diff --git a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/slack/SlackDemoPanelButton.kt b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/slack/SlackDemoPanelButton.kt index 71daae50..4cb89ee5 100644 --- a/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/slack/SlackDemoPanelButton.kt +++ b/sample/common/src/commonMain/kotlin/com/mohamedrejeb/richeditor/sample/common/slack/SlackDemoPanelButton.kt @@ -2,15 +2,11 @@ package com.mohamedrejeb.richeditor.sample.common.slack import androidx.compose.foundation.background import androidx.compose.foundation.clickable -import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material.ripple.rememberRipple import androidx.compose.material3.* import androidx.compose.runtime.Composable -import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip @@ -19,7 +15,6 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.semantics.Role import androidx.compose.ui.unit.dp -import org.jetbrains.compose.resources.painterResource @Composable fun SlackDemoPanelButton( @@ -40,8 +35,6 @@ fun SlackDemoPanelButton( onClick = onClick, enabled = true, role = Role.Button, - interactionSource = remember { MutableInteractionSource() }, - indication = rememberRipple() ), contentAlignment = Alignment.Center ) { From cf6c17c054023b5348adfae0ca496b5f1c5f0e70 Mon Sep 17 00:00:00 2001 From: MohamedRejeb Date: Sun, 10 Nov 2024 14:28:14 +0100 Subject: [PATCH 5/5] Run kotlinUpgradeYarnLock --- kotlin-js-store/yarn.lock | 37 ------------------------------------- 1 file changed, 37 deletions(-) diff --git a/kotlin-js-store/yarn.lock b/kotlin-js-store/yarn.lock index c7149f8b..c42a21ef 100644 --- a/kotlin-js-store/yarn.lock +++ b/kotlin-js-store/yarn.lock @@ -429,13 +429,6 @@ resolved "https://registry.yarnpkg.com/@xtuc/long/-/long-4.2.2.tgz#d291c6a4e97989b5c61d9acf396ae4fe133a718d" integrity sha512-NuHqBY1PB/D8xU6s/thBgOAiAP7HOYDQ32+BFZILJ8ivkUkAHQnWfn6WhL79Owj1qmUnoN/YPhktdIoucipkAQ== -abort-controller@3.0.0: - version "3.0.0" - resolved "https://registry.yarnpkg.com/abort-controller/-/abort-controller-3.0.0.tgz#eaf54d53b62bae4138e809ca225c8439a6efb392" - integrity sha512-h8lQ8tacZYnR3vNQTgibj+tODHI5/+l06Au2Pcriv/Gmet0eaj4TwWH41sO9wnHDiQsEj19q0drzdWdeAHtweg== - dependencies: - event-target-shim "^5.0.0" - accepts@~1.3.4, accepts@~1.3.5, accepts@~1.3.8: version "1.3.8" resolved "https://registry.yarnpkg.com/accepts/-/accepts-1.3.8.tgz#0bf0be125b67014adcb0b0921e62db7bffe16b2e" @@ -1058,11 +1051,6 @@ etag@~1.8.1: resolved "https://registry.yarnpkg.com/etag/-/etag-1.8.1.tgz#41ae2eeb65efa62268aebfea83ac7d79299b0887" integrity sha512-aIL5Fx7mawVa300al2BnEE4iNvo1qETxLrPI/o05L7z6go7fCw1J6EQmbK4FmJ2AS7kgVF/KEZWufBfdClMcPg== -event-target-shim@^5.0.0: - version "5.0.1" - resolved "https://registry.yarnpkg.com/event-target-shim/-/event-target-shim-5.0.1.tgz#5d4d3ebdf9583d63a5333ce2deb7480ab2b05789" - integrity sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ== - eventemitter3@^4.0.0: version "4.0.7" resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-4.0.7.tgz#2de9b68f6528d5644ef5c59526a1b4a07306169f" @@ -1880,13 +1868,6 @@ neo-async@^2.6.2: resolved "https://registry.yarnpkg.com/neo-async/-/neo-async-2.6.2.tgz#b4aafb93e3aeb2d8174ca53cf163ab7d7308305f" integrity sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw== -node-fetch@2.6.7: - version "2.6.7" - resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad" - integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ== - dependencies: - whatwg-url "^5.0.0" - node-forge@^1: version "1.3.1" resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-1.3.1.tgz#be8da2af243b2417d5f646a770663a92b7e9ded3" @@ -2584,11 +2565,6 @@ toidentifier@1.0.1: resolved "https://registry.yarnpkg.com/toidentifier/-/toidentifier-1.0.1.tgz#3be34321a88a820ed1bd80dfaa33e479fbb8dd35" integrity sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA== -tr46@~0.0.3: - version "0.0.3" - resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a" - integrity sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw== - type-is@~1.6.18: version "1.6.18" resolved "https://registry.yarnpkg.com/type-is/-/type-is-1.6.18.tgz#4e552cd05df09467dcbc4ef739de89f2cf37c131" @@ -2672,11 +2648,6 @@ wbuf@^1.1.0, wbuf@^1.7.3: dependencies: minimalistic-assert "^1.0.0" -webidl-conversions@^3.0.0: - version "3.0.1" - resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871" - integrity sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ== - webpack-cli@5.1.4: version "5.1.4" resolved "https://registry.yarnpkg.com/webpack-cli/-/webpack-cli-5.1.4.tgz#c8e046ba7eaae4911d7e71e2b25b776fcc35759b" @@ -2807,14 +2778,6 @@ websocket-extensions@>=0.1.1: resolved "https://registry.yarnpkg.com/websocket-extensions/-/websocket-extensions-0.1.4.tgz#7f8473bc839dfd87608adb95d7eb075211578a42" integrity sha512-OqedPIGOfsDlo31UNwYbCFMSaO9m9G/0faIHj5/dZFDMFqPTcx6UwqyOy3COEaEOg/9VsGIpdqn62W5KhoKSpg== -whatwg-url@^5.0.0: - version "5.0.0" - resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d" - integrity sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw== - dependencies: - tr46 "~0.0.3" - webidl-conversions "^3.0.0" - which@^1.2.1: version "1.3.1" resolved "https://registry.yarnpkg.com/which/-/which-1.3.1.tgz#a45043d54f5805316da8d62f9f50918d3da70b0a"