Skip to content

Commit b4c624f

Browse files
committed
Adding in a potential fix for @ mention issues
1 parent a678065 commit b4c624f

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

richeditor-compose/src/commonMain/kotlin/com/mohamedrejeb/richeditor/parser/lexical/RichTextStateLexicalParser.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -620,11 +620,11 @@ internal object RichTextStateLexicalParser : RichTextStateParser<String> {
620620
val patterns = listOf("\"$fieldName\":\"", "\"$fieldName\": \"")
621621

622622
for (pattern in patterns) {
623-
val startIndex = if (fieldName == "type") {
624-
json.lastIndexOf(pattern)
625-
} else {
626-
json.indexOf(pattern)
627-
}
623+
// FIX: Always use indexOf (first occurrence) instead of lastIndexOf
624+
// Using lastIndexOf for "type" causes wrong extraction when nodes have nested children
625+
// Example: {"type":"paragraph","children":[{"type":"mention"}]}
626+
// Would incorrectly extract "mention" instead of "paragraph"
627+
val startIndex = json.indexOf(pattern)
628628

629629
if (startIndex != -1) {
630630
val valueStart = startIndex + pattern.length

0 commit comments

Comments
 (0)