@@ -137,6 +137,16 @@ namespace fcitx {
137137 }
138138 }
139139
140+ void LotusState::send_backspace_forward (int count) const {
141+ if (count <= 0 )
142+ return ;
143+ for (int i = 0 ; i < count - 1 ; ++i) {
144+ ic_->forwardKey (Key (FcitxKey_BackSpace, KeyState::NoState), false );
145+ ic_->forwardKey (Key (FcitxKey_BackSpace, KeyState::NoState), true );
146+ }
147+ send_backspace_uinput (0 ); // trigger 1bs to make all bs prev release
148+ }
149+
140150 void LotusState::replayBufferToEngine (const std::string& buffer) {
141151 if (lotusEngine_.handle () == 0U )
142152 return ;
@@ -469,13 +479,14 @@ namespace fcitx {
469479 LOTUS_INFO (" Skip retry" );
470480 } else {
471481 // Retry x5 (1 ms each), khi can (chromium,electron,...)
472- for (int retry = 0 ; retry < 5 ; ++retry) {
473- std::this_thread::sleep_for (std::chrono::milliseconds (1 ));
474- const auto & surr2 = ic_->surroundingText ();
475- if (surr2.isValid () && surr2.cursor () == realtextLen.load (std::memory_order_acquire)) {
476- break ;
482+ if (waitAck_)
483+ for (int retry = 0 ; retry < 5 ; ++retry) {
484+ std::this_thread::sleep_for (std::chrono::milliseconds (1 ));
485+ const auto & surr2 = ic_->surroundingText ();
486+ if (surr2.isValid () && surr2.cursor () == realtextLen.load (std::memory_order_acquire)) {
487+ break ;
488+ }
477489 }
478- }
479490 }
480491 ic_->commitString (pending_commit_string_);
481492 LOTUS_INFO (" Commit: " + pending_commit_string_);
@@ -530,6 +541,7 @@ namespace fcitx {
530541 replacement_start_ms_.store (now_ms (), std::memory_order_release);
531542 is_deleting_.store (true , std::memory_order_release);
532543 monitor_cv.notify_one ();
544+ // send_backspace_forward(expected_backspaces_ - 1);
533545 send_backspace_uinput (expected_backspaces_);
534546 LOTUS_INFO (" Send " + std::to_string (expected_backspaces_) + " backspaces" );
535547 }
0 commit comments