Skip to content

Commit 5c53cdb

Browse files
committed
only need retry for chromium,electron ack
1 parent c34b9c8 commit 5c53cdb

3 files changed

Lines changed: 23 additions & 11 deletions

File tree

src/lotus-engine.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -617,10 +617,10 @@ namespace fcitx {
617617
}
618618

619619
void LotusEngine::deactivate(const InputMethodEntry& /*entry*/, InputContextEvent& event) {
620-
auto* ic = event.inputContext();
621-
auto* state = ic->propertyFor(&factory_);
622-
const bool surrvalid = ic->surroundingText().isValid();
623-
const bool is_dbus = getFrontendName(ic) == "dbus";
620+
auto* ic = event.inputContext();
621+
auto* state = ic->propertyFor(&factory_);
622+
const bool surrvalid = ic->surroundingText().isValid();
623+
const bool is_dbus = getFrontendName(ic) == "dbus";
624624
if (realMode == LotusMode::Preedit && event.type() != EventType::InputContextFocusOut) {
625625
state->commitBuffer();
626626
} else {

src/lotus-state.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/lotus-state.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ namespace fcitx {
126126
* @param count Number of backspaces to send.
127127
*/
128128
void send_backspace_uinput(int count) const;
129-
129+
void send_backspace_forward(int count) const;
130130
/**
131131
* @brief Replays buffer content to the engine.
132132
* @param buffer The string buffer to replay.

0 commit comments

Comments
 (0)