diff --git a/src/main/java/io/github/homchom/recode/feature/visual/EditBoxExpressionFormatter.kt b/src/main/java/io/github/homchom/recode/feature/visual/EditBoxExpressionFormatter.kt index 9315656d..0ff61f9d 100644 --- a/src/main/java/io/github/homchom/recode/feature/visual/EditBoxExpressionFormatter.kt +++ b/src/main/java/io/github/homchom/recode/feature/visual/EditBoxExpressionFormatter.kt @@ -119,7 +119,7 @@ class EditBoxExpressionFormatter( min(startIndex, partialEnd) - partialStart )) - if (partialRange.first in startIndex.. - var index = 0 - var adjustedIndex = 0 - accept { _, style, codePoint -> - if (index++ in startIndex.. + if (index in startIndex.. + val shouldContinue = sink.accept(absoluteIndex++, style, codePoint) + if (String.fromCodePoint(codePoint)[0].isHighSurrogate()) { + absoluteIndex++ + } + shouldContinue + } +} \ No newline at end of file diff --git a/src/main/java/io/github/homchom/recode/util/BasicTypeExtensions.kt b/src/main/java/io/github/homchom/recode/util/BasicTypeExtensions.kt index 06d1c4f0..05fd42f6 100644 --- a/src/main/java/io/github/homchom/recode/util/BasicTypeExtensions.kt +++ b/src/main/java/io/github/homchom/recode/util/BasicTypeExtensions.kt @@ -11,6 +11,11 @@ fun Boolean.unitOrNull() = if (this) Unit else null // strings +/** + * @see Character.toString + */ +fun String.Companion.fromCodePoint(codePoint: Int): String = Character.toString(codePoint) + /** * Appends multiple [substrings] to this [StringBuilder]. */