Skip to content

Commit

Permalink
refactor: move (commit/clear)Composition to new api interface
Browse files Browse the repository at this point in the history
Also implement `postRimeJob` to execute rime api function sequentially, which may fix "lateinit property `activeTheme` uninitialized" issue.
Replace `performEscape` with `clearComposition` to reset the input context of rime.
  • Loading branch information
WhiredPlanck committed Jun 25, 2024
1 parent 1f1c0a6 commit 2b604c5
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 136 deletions.
19 changes: 8 additions & 11 deletions app/src/main/java/com/osfans/trime/core/Rime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ class Rime : RimeApi, RimeLifecycleOwner {

override suspend fun selectSchema(schemaId: String) = withRimeContext { selectRimeSchema(schemaId) }

override suspend fun commitComposition(): Boolean = withRimeContext { commitRimeComposition().also { updateContext() } }

override suspend fun clearComposition() =
withRimeContext {
clearRimeComposition()
updateContext()
}

fun startup(fullCheck: Boolean) {
if (lifecycle.currentStateFlow.value != RimeLifecycle.State.STOPPED) {
Timber.w("Skip starting rime: not at stopped state!")
Expand Down Expand Up @@ -245,17 +253,6 @@ class Rime : RimeApi, RimeLifecycleOwner {
val candHighlightIndex: Int
get() = if (isComposing) inputContext?.menu?.highlightedCandidateIndex ?: -1 else -1

fun commitComposition(): Boolean {
return commitRimeComposition().also {
updateContext()
}
}

fun clearComposition() {
clearRimeComposition()
updateContext()
}

fun selectCandidate(index: Int): Boolean {
return selectRimeCandidateOnCurrentPage(index).also {
updateContext()
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/osfans/trime/core/RimeApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ interface RimeApi {
suspend fun selectedSchemaId(): String

suspend fun selectSchema(schemaId: String): Boolean

suspend fun commitComposition(): Boolean

suspend fun clearComposition()
}
Loading

0 comments on commit 2b604c5

Please sign in to comment.