Skip to content

Commit

Permalink
fix(chord_composer): should clear raw input after committing text
Browse files Browse the repository at this point in the history
  • Loading branch information
lotem committed Feb 7, 2021
1 parent 2fd78c1 commit 79b34ab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/rime/gear/chord_composer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ ProcessResult ChordComposer::ProcessChordingKey(const KeyEvent& key_event) {
return kNoop;
}
// chording key
editing_chord_ = true;
bool is_key_up = key_event.release();
if (is_key_up) {
if (pressed_.erase(ch) != 0 && pressed_.empty()) {
Expand All @@ -114,6 +115,7 @@ ProcessResult ChordComposer::ProcessChordingKey(const KeyEvent& key_event) {
if (updated)
UpdateChord();
}
editing_chord_ = false;
return kAccepted;
}

Expand Down Expand Up @@ -180,13 +182,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()) {
sending_chord_ = true;
for (const KeyEvent& key : key_sequence) {
if (!engine_->ProcessKey(key)) {
// direct commit
Expand All @@ -195,8 +197,8 @@ void ChordComposer::FinishChord() {
raw_sequence_.clear();
}
}
sending_chord_ = false;
}
sending_chord_ = false;
}

void ChordComposer::ClearChord() {
Expand Down Expand Up @@ -224,7 +226,7 @@ void ChordComposer::OnContextUpdate(Context* ctx) {
}
else if (composing_) {
composing_ = false;
if (!sending_chord_) {
if (!editing_chord_ || sending_chord_) {
raw_sequence_.clear();
DLOG(INFO) << "clear raw sequence.";
}
Expand Down
1 change: 1 addition & 0 deletions src/rime/gear/chord_composer.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class ChordComposer : public Processor {

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

0 comments on commit 79b34ab

Please sign in to comment.