From 2b258611845da6543004673c011812d2c417dac4 Mon Sep 17 00:00:00 2001 From: Chen Gong Date: Thu, 4 Feb 2021 00:41:04 +0800 Subject: [PATCH] fix(chord_composer): press Return key to commit raw key sequence With a previous code change, the context went through a non-composing state while FinishChord() was calling ClearChord() which removes the placeholder input. OnContextUpdate() responded to that intermediate change and cleared raw_sequence when it shouldn't. Skip that OnContextUpdate() event by flipping the sending_chord_ flag. --- src/rime/gear/chord_composer.cc | 12 +++++++----- src/rime/gear/chord_composer.h | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/rime/gear/chord_composer.cc b/src/rime/gear/chord_composer.cc index dc293a82f..432161d47 100644 --- a/src/rime/gear/chord_composer.cc +++ b/src/rime/gear/chord_composer.cc @@ -126,7 +126,7 @@ ProcessResult ChordComposer::ProcessKeyEvent(const KeyEvent& key_event) { if (engine_->context()->get_option("ascii_mode")) { return kNoop; } - if (pass_thru_) { + if (sending_chord_) { return ProcessFunctionKey(key_event); } bool is_key_up = key_event.release(); @@ -180,13 +180,13 @@ void ChordComposer::UpdateChord() { void ChordComposer::FinishChord() { if (!engine_) return; + sending_chord_ = true; string code = SerializeChord(); output_format_.Apply(&code); ClearChord(); KeySequence key_sequence; if (key_sequence.Parse(code) && !key_sequence.empty()) { - pass_thru_ = true; for (const KeyEvent& key : key_sequence) { if (!engine_->ProcessKey(key)) { // direct commit @@ -195,8 +195,8 @@ void ChordComposer::FinishChord() { raw_sequence_.clear(); } } - pass_thru_ = false; } + sending_chord_ = false; } void ChordComposer::ClearChord() { @@ -224,8 +224,10 @@ void ChordComposer::OnContextUpdate(Context* ctx) { } else if (composing_) { composing_ = false; - raw_sequence_.clear(); - DLOG(INFO) << "clear raw sequence."; + if (!sending_chord_) { + raw_sequence_.clear(); + DLOG(INFO) << "clear raw sequence."; + } } } diff --git a/src/rime/gear/chord_composer.h b/src/rime/gear/chord_composer.h index 39413aa0a..21d2e89a7 100644 --- a/src/rime/gear/chord_composer.h +++ b/src/rime/gear/chord_composer.h @@ -44,7 +44,7 @@ class ChordComposer : public Processor { set pressed_; set chord_; - bool pass_thru_ = false; + bool sending_chord_ = false; bool composing_ = false; string raw_sequence_; connection update_connection_;