@@ -141,9 +141,7 @@ std::string MacosFrontend::keyEvent(ICUUID uuid, const Key &key, bool isRelease,
141141 auto timeEventPtr = timeEvent.release ();
142142 }
143143
144- auto state = ic->getState (keyEvent.accepted ());
145- ic->resetState ();
146- return state;
144+ return ic->popState (keyEvent.accepted ());
147145}
148146
149147MacosInputContext *MacosFrontend::findIC (ICUUID uuid) {
@@ -212,7 +210,7 @@ void MacosFrontend::focusIn(ICUUID uuid, bool isPassword) {
212210 useAppDefaultIM (program);
213211}
214212
215- std::string MacosFrontend::focusOut (ICUUID uuid) {
213+ std::string MacosFrontend::commitComposition (ICUUID uuid) {
216214 auto *ic = findIC (uuid);
217215 if (!ic)
218216 return " {}" ;
@@ -230,13 +228,18 @@ std::string MacosFrontend::focusOut(ICUUID uuid) {
230228 // At this stage panel is still shown. If removed, a following backspace
231229 // will commit a BS character in VSCode.
232230 ic->setDummyPreedit (false );
233- auto state = ic->getState (false );
231+ auto state = ic->popState (false );
234232 ic->isSyncEvent = false ;
235233
234+ return state;
235+ }
236+
237+ void MacosFrontend::focusOut (ICUUID uuid) {
238+ auto *ic = findIC (uuid);
239+ if (!ic)
240+ return ;
236241 FCITX_INFO () << " Focus out " << ic->program ();
237242 ic->focusOut ();
238-
239- return state;
240243}
241244
242245MacosInputContext::MacosInputContext (MacosFrontend *frontend,
@@ -274,13 +277,14 @@ void MacosInputContext::updatePreeditImpl() {
274277 state_.caretPos = preedit.cursor ();
275278}
276279
277- std::string MacosInputContext::getState (bool accepted) {
280+ std::string MacosInputContext::popState (bool accepted) {
278281 nlohmann::json j;
279282 j[" commit" ] = state_.commit ;
280283 j[" preedit" ] = state_.preedit ;
281284 j[" caretPos" ] = state_.caretPos ;
282285 j[" dummyPreedit" ] = state_.dummyPreedit ;
283286 j[" accepted" ] = accepted;
287+ resetState ();
284288 return j.dump ();
285289}
286290
@@ -345,7 +349,12 @@ void focus_in(ICUUID uuid, bool isPassword) noexcept {
345349 });
346350}
347351
348- std::string focus_out (ICUUID uuid) noexcept {
349- return with_fcitx (
350- [=](Fcitx &fcitx) { return fcitx.frontend ()->focusOut (uuid); });
352+ std::string commit_composition (ICUUID uuid) noexcept {
353+ return with_fcitx ([=](Fcitx &fcitx) {
354+ return fcitx.frontend ()->commitComposition (uuid);
355+ });
356+ }
357+
358+ void focus_out (ICUUID uuid) noexcept {
359+ with_fcitx ([=](Fcitx &fcitx) { return fcitx.frontend ()->focusOut (uuid); });
351360}
0 commit comments