From 7630d62a3925c385db386e295e5438ce3eb3d51f Mon Sep 17 00:00:00 2001 From: "morse.hsiao" <6482586+imfuxiao@users.noreply.github.com> Date: Sun, 17 Dec 2023 12:54:23 +0800 Subject: [PATCH] feat(rime_api): add RimeApi::set_input (#771) resolve #547 --- src/rime_api.cc | 12 ++++++++++++ src/rime_api.h | 3 +++ 2 files changed, 15 insertions(+) diff --git a/src/rime_api.cc b/src/rime_api.cc index e3e0a27bd9..678169c0af 100644 --- a/src/rime_api.cc +++ b/src/rime_api.cc @@ -1084,6 +1084,17 @@ const char* RimeGetStateLabel(RimeSessionId session_id, .str; } +RIME_API Bool RimeSetInput(RimeSessionId session_id, const char* input) { + an session(Service::instance().GetSession(session_id)); + if (!session) + return False; + Context* ctx = session->context(); + if (!ctx) + return False; + ctx->set_input(input); + return True; +} + RIME_API RimeApi* rime_get_api() { static RimeApi s_api = {0}; if (!s_api.data_size) { @@ -1177,6 +1188,7 @@ RIME_API RimeApi* rime_get_api() { s_api.delete_candidate = &RimeDeleteCandidate; s_api.delete_candidate_on_current_page = &RimeDeleteCandidateOnCurrentPage; s_api.get_state_label_abbreviated = &RimeGetStateLabelAbbreviated; + s_api.set_input = &RimeSetInput; } return &s_api; } diff --git a/src/rime_api.h b/src/rime_api.h index ae4467abc8..54fd4c1409 100644 --- a/src/rime_api.h +++ b/src/rime_api.h @@ -387,6 +387,7 @@ RIME_API Bool RimeConfigUpdateSignature(RimeConfig* config, const char* signer); RIME_API Bool RimeSimulateKeySequence(RimeSessionId session_id, const char* key_sequence); +RIME_API Bool RimeSetInput(RimeSessionId session_id, const char* input); // Module /*! @@ -644,6 +645,8 @@ typedef struct rime_api_t { const char* option_name, Bool state, Bool abbreviated); + + Bool (*set_input)(RimeSessionId session_id, const char* input); } RimeApi; //! API entry