Skip to content

Commit e5f7309

Browse files
committed
feat(jni): add selectRimeCanidate and forgetRimeCandidate APIs
Useful when get bulk candidates
1 parent 74430fa commit e5f7309

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ class Rime : RimeApi, RimeLifecycleOwner {
7070
getCurrentRimeSchema() == ".default" // 無方案
7171
}
7272

73+
override suspend fun selectCandidate(idx: Int): Boolean =
74+
withRimeContext {
75+
selectRimeCandidate(idx).also { if (it) updateContext() }
76+
}
77+
78+
override suspend fun forgetCandidate(idx: Int): Boolean =
79+
withRimeContext {
80+
forgetRimeCandidate(idx).also { if (it) updateContext() }
81+
}
82+
7383
override suspend fun availableSchemata(): Array<SchemaItem> = withRimeContext { getAvailableRimeSchemaList() }
7484

7585
override suspend fun enabledSchemata(): Array<SchemaItem> = withRimeContext { getSelectedRimeSchemaList() }
@@ -421,6 +431,12 @@ class Rime : RimeApi, RimeLifecycleOwner {
421431
@JvmStatic
422432
external fun deleteRimeCandidateOnCurrentPage(index: Int): Boolean
423433

434+
@JvmStatic
435+
external fun selectRimeCandidate(index: Int): Boolean
436+
437+
@JvmStatic
438+
external fun forgetRimeCandidate(index: Int): Boolean
439+
424440
@JvmStatic
425441
external fun getLibrimeVersion(): String
426442

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ interface RimeApi {
1717

1818
suspend fun isEmpty(): Boolean
1919

20+
suspend fun selectCandidate(idx: Int): Boolean
21+
22+
suspend fun forgetCandidate(idx: Int): Boolean
23+
2024
suspend fun availableSchemata(): Array<SchemaItem>
2125

2226
suspend fun enabledSchemata(): Array<SchemaItem>

app/src/main/jni/librime_jni/rime_jni.cc

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ class Rime {
114114
return rime->delete_candidate_on_current_page(session, index);
115115
}
116116

117+
bool selectCandidate(size_t index) {
118+
return rime->select_candidate(session, index);
119+
}
120+
121+
bool forgetCandidate(size_t index) {
122+
return rime->delete_candidate(session, index);
123+
}
124+
117125
std::string stateLabel(const std::string &optionName, bool state) {
118126
return rime->get_state_label(session, optionName.c_str(), state);
119127
}
@@ -443,6 +451,26 @@ Java_com_osfans_trime_core_Rime_deleteRimeCandidateOnCurrentPage(
443451
return Rime::Instance().deleteCandidateOnCurrentPage(index);
444452
}
445453

454+
extern "C" JNIEXPORT jboolean JNICALL
455+
Java_com_osfans_trime_core_Rime_selectRimeCandidate(JNIEnv *env,
456+
jclass /* thiz */,
457+
jint index) {
458+
if (!is_rime_running()) {
459+
return false;
460+
}
461+
return Rime::Instance().selectCandidate(index);
462+
}
463+
464+
extern "C" JNIEXPORT jboolean JNICALL
465+
Java_com_osfans_trime_core_Rime_forgetRimeCandidate(JNIEnv *env,
466+
jclass /* thiz */,
467+
jint index) {
468+
if (!is_rime_running()) {
469+
return false;
470+
}
471+
return Rime::Instance().forgetCandidate(index);
472+
}
473+
446474
extern "C" JNIEXPORT jstring JNICALL
447475
Java_com_osfans_trime_core_Rime_getLibrimeVersion(JNIEnv *env,
448476
jclass /* thiz */) {

0 commit comments

Comments
 (0)