Skip to content

Commit

Permalink
chore(chord_composer): non-chord key clears state
Browse files Browse the repository at this point in the history
  • Loading branch information
lotem committed Mar 12, 2024
1 parent 1496dc1 commit 9184ae6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/rime/gear/chord_composer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,13 @@ ProcessResult ChordComposer::ProcessFunctionKey(const KeyEvent& key_event) {
raw_sequence_.clear();
}
ClearChord();
state_.Clear();

} else if (ch == XK_BackSpace || ch == XK_Escape) {
// clear the raw sequence
raw_sequence_.clear();
ClearChord();
state_.Clear();
}
return kNoop;
}
Expand Down Expand Up @@ -103,13 +106,15 @@ ProcessResult ChordComposer::ProcessChordingKey(const KeyEvent& key_event) {
(key_event.shift() && !use_shift_) ||
(key_event.super() && !use_super_) || (key_event.caps() && !use_caps_)) {
ClearChord();
state_.Clear();
return kNoop;
}
int ch = get_base_layer_key_code(key_event);
// non chording key
if (std::find(chording_keys_.begin(), chording_keys_.end(),
KeyEvent{ch, 0}) == chording_keys_.end()) {
ClearChord();
state_.Clear();
return kNoop;
}
// chording key
Expand All @@ -119,6 +124,7 @@ ProcessResult ChordComposer::ProcessChordingKey(const KeyEvent& key_event) {
if (state_.ReleaseKey(ch) && FinishChordConditionIsMet() &&
!state_.recognized_chord.empty()) {
FinishChord(state_.recognized_chord);
state_.recognized_chord.clear();
}
} else { // key down, ignore repeated key down events
if (state_.PressKey(ch) && state_.AddKeyToChord(ch)) {
Expand Down Expand Up @@ -206,7 +212,6 @@ void ChordComposer::FinishChord(const Chord& chord) {
}

void ChordComposer::ClearChord() {
state_.ClearChord();
if (!engine_)
return;
Context* ctx = engine_->context();
Expand Down
5 changes: 4 additions & 1 deletion src/rime/gear/chord_composer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ struct ChordingState {

bool AddKeyToChord(int ch) { return recognized_chord.insert(ch).second; }

void ClearChord() { recognized_chord.clear(); }
void Clear() {
pressed_keys.clear();
recognized_chord.clear();
}
};

class ChordComposer : public Processor {
Expand Down

0 comments on commit 9184ae6

Please sign in to comment.