Skip to content

Commit 7925458

Browse files
committed
fix: metrics of strings in RimeProto were not completely converted
1 parent 7e86995 commit 7925458

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

app/src/main/java/com/osfans/trime/core/RimeProto.kt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,29 @@ class RimeProto {
1919
val composition: Composition,
2020
val menu: Menu,
2121
val input: String,
22-
val caretPos: Int,
22+
private val _caretPos: Int,
2323
) {
24+
/**
25+
* Same with [Composition.cursorPos], just directly assign to it.
26+
*/
27+
val caretPos = composition.cursorPos
28+
2429
data class Composition(
25-
val length: Int = 0,
26-
val cursorPos: Int = 0,
30+
private val _length: Int = 0,
31+
private val _cursorPos: Int = 0,
2732
private val _selStart: Int = 0,
2833
private val _selEnd: Int = 0,
2934
val preedit: String? = null,
3035
val commitTextPreview: String? = null,
3136
) {
37+
/**
38+
* Actually we can directly use [String.length] on [preedit], but
39+
* we add it here for the sake of completeness as it is semantically correct
40+
*/
41+
val length: Int = preedit.run { if (isNullOrEmpty()) 0 else String(toByteArray(), 0, _length).length }
42+
43+
val cursorPos: Int = preedit.run { if (isNullOrEmpty()) 0 else String(toByteArray(), 0, _cursorPos).length }
44+
3245
val selStart: Int = preedit.run { if (isNullOrEmpty()) 0 else String(toByteArray(), 0, _selStart).length }
3346

3447
val selEnd: Int = preedit.run { if (isNullOrEmpty()) 0 else String(toByteArray(), 0, _selEnd).length }

0 commit comments

Comments
 (0)