Skip to content

Commit

Permalink
feat(selector): handle repeated key until release
Browse files Browse the repository at this point in the history
in horizontal mode, Left key highlights the previous candidate,
and fall back to navigator when already at the first candidate.
when Left is held down, do not fall back until the next key press.
  • Loading branch information
lotem committed Jan 24, 2023
1 parent d79f6b3 commit 8d93e9f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/rime/gear/selector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,14 @@ inline static bool is_linear_layout(Context* ctx) {
}

ProcessResult Selector::ProcessKeyEvent(const KeyEvent& key_event) {
if (key_event.release() || key_event.alt())
if (key_event.release()) {
last_key_ = 0;
key_repeat_ = 0;
return kNoop;
}
if (key_event.alt() || key_event.super())
return kNoop;

Context* ctx = engine_->context();
if (ctx->composition().empty())
return kNoop;
Expand All @@ -133,11 +139,18 @@ ProcessResult Selector::ProcessKeyEvent(const KeyEvent& key_event) {
is_linear_layout(ctx) ? Linear : Stacked;
auto result = KeyBindingProcessor::ProcessKeyEvent(
key_event, ctx, text_orientation | candidate_list_layout);

int ch = key_event.keycode();
if (result != kNoop) {
if (last_key_ == ch) {
++key_repeat_;
} else {
last_key_ = ch;
key_repeat_ = 1;
}
return result;
}

int ch = key_event.keycode();
int index = -1;
const string& select_keys(engine_->schema()->select_keys());
if (!select_keys.empty() &&
Expand Down Expand Up @@ -210,8 +223,9 @@ bool Selector::PreviousCandidate(Context* ctx) {
return false;
int index = comp.back().selected_index;
if (index <= 0) {
// in case of linear layout, fall back to navigator
return !is_linear_layout(ctx);
// in case of linear layout, fall back to navigator;
// repeated key press should be handled by the same processor.
return !is_linear_layout(ctx) || key_repeat_ > 0;
}
comp.back().selected_index = index - 1;
comp.back().tags.insert("paging");
Expand Down Expand Up @@ -256,7 +270,6 @@ bool Selector::End(Context* ctx) {
return Home(ctx);
}


bool Selector::SelectCandidateAt(Context* ctx, int index) {
Composition& comp = ctx->composition();
if (comp.empty())
Expand Down
4 changes: 4 additions & 0 deletions src/rime/gear/selector.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class Selector : public Processor, public KeyBindingProcessor<Selector, 4> {
Handler End;

bool SelectCandidateAt(Context* ctx, int index);

private:
int last_key_ = 0;
int key_repeat_ = 0;
};

} // namespace rime
Expand Down

0 comments on commit 8d93e9f

Please sign in to comment.