Skip to content

Commit

Permalink
fix(chord_composer): press Return key to commit raw key sequence
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lotem committed Feb 3, 2021
1 parent 7d9ad77 commit 2b25861
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
12 changes: 7 additions & 5 deletions src/rime/gear/chord_composer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -195,8 +195,8 @@ void ChordComposer::FinishChord() {
raw_sequence_.clear();
}
}
pass_thru_ = false;
}
sending_chord_ = false;
}

void ChordComposer::ClearChord() {
Expand Down Expand Up @@ -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.";
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/rime/gear/chord_composer.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class ChordComposer : public Processor {

set<int> pressed_;
set<int> chord_;
bool pass_thru_ = false;
bool sending_chord_ = false;
bool composing_ = false;
string raw_sequence_;
connection update_connection_;
Expand Down

0 comments on commit 2b25861

Please sign in to comment.