Skip to content

Commit e0617c3

Browse files
committed
feat: rime_api add RimeApi::RimeReplaceInput
resolve rime#547
1 parent ba7b47a commit e0617c3

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

src/rime/context.cc

+6
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,12 @@ void Context::set_input(const string& value) {
254254
update_notifier_(this);
255255
}
256256

257+
void Context::replace_input(size_t pos, size_t count, const string& value) {
258+
input_.replace(pos, count, value);
259+
caret_pos_ = input_.length();
260+
update_notifier_(this);
261+
}
262+
257263
void Context::set_option(const string& name, bool value) {
258264
options_[name] = value;
259265
option_update_notifier_(this, name);

src/rime/context.h

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class Context {
5858

5959
void set_input(const string& value);
6060
const string& input() const { return input_; }
61+
void replace_input(size_t pos, size_t count, const string& value);
6162

6263
void set_caret_pos(size_t caret_pos);
6364
size_t caret_pos() const { return caret_pos_; }

src/rime_api.cc

+13
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,18 @@ const char* RimeGetStateLabel(RimeSessionId session_id,
10831083
.str;
10841084
}
10851085

1086+
RIME_API Bool RimeReplaceInput(RimeSessionId session_id, size_t pos, size_t count, const char *replace_char) {
1087+
an<Session> session(Service::instance().GetSession(session_id));
1088+
if (!session)
1089+
return False;
1090+
Context *ctx = session->context();
1091+
if (!ctx)
1092+
return False;
1093+
ctx->replace_input(pos, count, replace_char);
1094+
return True;
1095+
}
1096+
1097+
10861098
RIME_API RimeApi* rime_get_api() {
10871099
static RimeApi s_api = {0};
10881100
if (!s_api.data_size) {
@@ -1176,6 +1188,7 @@ RIME_API RimeApi* rime_get_api() {
11761188
s_api.delete_candidate = &RimeDeleteCandidate;
11771189
s_api.delete_candidate_on_current_page = &RimeDeleteCandidateOnCurrentPage;
11781190
s_api.get_state_label_abbreviated = &RimeGetStateLabelAbbreviated;
1191+
s_api.replace_input = &RimeReplaceInput;
11791192
}
11801193
return &s_api;
11811194
}

src/rime_api.h

+8
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,7 @@ RIME_API void RimeCleanupAllSessions(void);
272272
// Input
273273

274274
RIME_API Bool RimeProcessKey(RimeSessionId session_id, int keycode, int mask);
275+
275276
/*!
276277
* return True if there is unread commit text
277278
*/
@@ -386,6 +387,7 @@ RIME_API Bool RimeConfigUpdateSignature(RimeConfig* config, const char* signer);
386387
RIME_API Bool RimeSimulateKeySequence(RimeSessionId session_id,
387388
const char* key_sequence);
388389

390+
RIME_API Bool RimeReplaceInput(RimeSessionId session_id, size_t pos, size_t count, const char* replace_char);
389391
// Module
390392

391393
/*!
@@ -643,6 +645,12 @@ typedef struct rime_api_t {
643645
const char* option_name,
644646
Bool state,
645647
Bool abbreviated);
648+
//! select a candidate from current page.
649+
Bool (*select_candidate_on_current_page)(RimeSessionId session_id,
650+
size_t index);
651+
652+
//! modify the current input
653+
Bool (*replace_input)(RimeSessionId session_id, size_t pos, size_t count, const char* replace_char);
646654
} RimeApi;
647655

648656
//! API entry

0 commit comments

Comments
 (0)