Skip to content

Commit

Permalink
fix: metrics of strings in RimeProto were not completely converted
Browse files Browse the repository at this point in the history
  • Loading branch information
WhiredPlanck committed Oct 8, 2024
1 parent 7e86995 commit 7925458
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions app/src/main/java/com/osfans/trime/core/RimeProto.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,29 @@ class RimeProto {
val composition: Composition,
val menu: Menu,
val input: String,
val caretPos: Int,
private val _caretPos: Int,
) {
/**
* Same with [Composition.cursorPos], just directly assign to it.
*/
val caretPos = composition.cursorPos

data class Composition(
val length: Int = 0,
val cursorPos: Int = 0,
private val _length: Int = 0,
private val _cursorPos: Int = 0,
private val _selStart: Int = 0,
private val _selEnd: Int = 0,
val preedit: String? = null,
val commitTextPreview: String? = null,
) {
/**
* Actually we can directly use [String.length] on [preedit], but
* we add it here for the sake of completeness as it is semantically correct
*/
val length: Int = preedit.run { if (isNullOrEmpty()) 0 else String(toByteArray(), 0, _length).length }

val cursorPos: Int = preedit.run { if (isNullOrEmpty()) 0 else String(toByteArray(), 0, _cursorPos).length }

val selStart: Int = preedit.run { if (isNullOrEmpty()) 0 else String(toByteArray(), 0, _selStart).length }

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

0 comments on commit 7925458

Please sign in to comment.