@@ -19,16 +19,29 @@ class RimeProto {
19
19
val composition : Composition ,
20
20
val menu : Menu ,
21
21
val input : String ,
22
- val caretPos : Int ,
22
+ private val _caretPos : Int ,
23
23
) {
24
+ /* *
25
+ * Same with [Composition.cursorPos], just directly assign to it.
26
+ */
27
+ val caretPos = composition.cursorPos
28
+
24
29
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 ,
27
32
private val _selStart : Int = 0 ,
28
33
private val _selEnd : Int = 0 ,
29
34
val preedit : String? = null ,
30
35
val commitTextPreview : String? = null ,
31
36
) {
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
+
32
45
val selStart: Int = preedit.run { if (isNullOrEmpty()) 0 else String (toByteArray(), 0 , _selStart ).length }
33
46
34
47
val selEnd: Int = preedit.run { if (isNullOrEmpty()) 0 else String (toByteArray(), 0 , _selEnd ).length }
0 commit comments