Skip to content

Commit b2f759e

Browse files
committed
Add an option to commit text when switch input method.
Close #13.
1 parent f86b185 commit b2f759e

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

src/rimeengine.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,12 @@ void RimeEngine::activate(const InputMethodEntry &, InputContextEvent &event) {
260260
void RimeEngine::deactivate(const InputMethodEntry &entry,
261261
InputContextEvent &event) {
262262
event.inputContext()->statusArea().clearGroup(StatusGroup::InputMethod);
263+
if (event.type() == EventType::InputContextSwitchInputMethod &&
264+
*config_.commitWhenDeactivate) {
265+
auto inputContext = event.inputContext();
266+
auto state = inputContext->propertyFor(&factory_);
267+
state->commitPreedit(inputContext);
268+
}
263269
reset(entry, event);
264270
}
265271
void RimeEngine::keyEvent(const InputMethodEntry &entry, KeyEvent &event) {

src/rimeengine.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ FCITX_CONFIGURATION(
3131
Option<bool> showPreeditInApplication{this, "PreeditInApplication",
3232
_("Show preedit within application"),
3333
false};
34+
Option<bool> commitWhenDeactivate{
35+
this, "Commit when deactivate.",
36+
_("Commit current text when deactivating."), true};
3437
Option<bool> autoloadPlugins{this, "AutoloadPlugins",
3538
_("Load available plugins automatically"),
3639
false};

src/rimestate.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,4 +214,17 @@ void RimeState::release() {
214214
session_ = 0;
215215
}
216216
}
217+
218+
void RimeState::commitPreedit(InputContext *ic) {
219+
if (auto api = engine_->api()) {
220+
RIME_STRUCT(RimeContext, context);
221+
if (!api->get_context(session_, &context)) {
222+
return;
223+
}
224+
if (context.commit_text_preview) {
225+
ic->commitString(context.commit_text_preview);
226+
}
227+
}
228+
}
229+
217230
} // namespace fcitx

src/rimestate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class RimeState : public InputContextProperty {
2323
void updatePreedit(InputContext *ic, const RimeContext &context);
2424
void updateUI(InputContext *ic, bool keyRelease);
2525
void release();
26+
void commitPreedit(InputContext *ic);
2627

2728
private:
2829
RimeEngine *engine_;

0 commit comments

Comments
 (0)