Skip to content

Commit

Permalink
feat(selector): support 4 combinations of horizontal/vertical text or…
Browse files Browse the repository at this point in the history
…ientation and stacked/linear candidate list layout
  • Loading branch information
lotem committed Sep 7, 2020
1 parent 2ed780b commit c498f71
Showing 1 changed file with 46 additions and 11 deletions.
57 changes: 46 additions & 11 deletions src/rime/gear/selector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@

namespace rime {

// Direction of candidate list.
using Direction = int;
constexpr Direction kDirectionVoid = -1;
constexpr Direction kDirectionDown = 0;
constexpr Direction kDirectionLeft = 1;
constexpr Direction kDirectionUp = 2;
constexpr Direction kDirectionRight = 3;

Selector::Selector(const Ticket& ticket) : Processor(ticket) {
}

Expand All @@ -28,6 +36,25 @@ ProcessResult Selector::ProcessKeyEvent(const KeyEvent& key_event) {
Segment& current_segment(ctx->composition().back());
if (!current_segment.menu || current_segment.HasTag("raw"))
return kNoop;
bool is_linear_candidate_list = ctx->get_option("_linear");
bool is_vertical_text = ctx->get_option("_vertical");
// Deprecated. equivalent to {_linear: true, _vertical: false}
bool is_horizontal_layout = ctx->get_option("_horizontal");
Direction next_candidate = kDirectionDown;
Direction next_page = kDirectionDown;
if (is_vertical_text) {
// +90 degrees
next_candidate = (next_candidate + 1) % 4;
next_page = (next_page + 1) % 4;
}
if (is_linear_candidate_list || is_horizontal_layout) {
// -90 degrees
next_candidate = (next_candidate + 3) % 4;
}
if (next_page == next_candidate) {
// this is no-op. just to clarify that arrow keys don't change page.
next_page = kDirectionVoid;
}
int ch = key_event.keycode();
if (ch == XK_Prior || ch == XK_KP_Prior) {
PageUp(ctx);
Expand All @@ -38,46 +65,54 @@ ProcessResult Selector::ProcessKeyEvent(const KeyEvent& key_event) {
return kAccepted;
}
if (ch == XK_Up || ch == XK_KP_Up) {
if (ctx->get_option("_horizontal")) {
PageUp(ctx);
} else {
if (next_candidate == kDirectionDown) {
CursorUp(ctx);
} else if (next_page == kDirectionDown) {
PageUp(ctx);
}
return kAccepted;
}
if (ch == XK_Down || ch == XK_KP_Down) {
if (ctx->get_option("_horizontal")) {
PageDown(ctx);
} else {
if (next_candidate == kDirectionDown) {
CursorDown(ctx);
} else if (next_page == kDirectionDown) {
PageDown(ctx);
}
return kAccepted;
}
if (ch == XK_Left || ch == XK_KP_Left) {
if (!key_event.ctrl() &&
!key_event.shift() &&
ctx->caret_pos() == ctx->input().length()) {
if (ctx->get_option("_horizontal") &&
if (next_candidate == kDirectionRight &&
CursorUp(ctx)) {
return kAccepted;
}
if (ctx->get_option("_vertical")) {
if (next_candidate == kDirectionLeft) {
CursorDown(ctx);
return kAccepted;
}
if (next_page == kDirectionLeft) {
PageDown(ctx);
return kAccepted;
}
}
return kNoop;
}
if (ch == XK_Right || ch == XK_KP_Right) {
if (!key_event.ctrl() &&
!key_event.shift() &&
ctx->caret_pos() == ctx->input().length()) {
if (ctx->get_option("_horizontal")) {
if (next_candidate == kDirectionRight) {
CursorDown(ctx);
return kAccepted;
}
if (ctx->get_option("_vertical") &&
CursorUp(ctx)) {
if (next_candidate == kDirectionLeft) {
CursorUp(ctx);
return kAccepted;
}
if (next_page == kDirectionLeft) {
PageUp(ctx);
return kAccepted;
}
}
Expand Down

0 comments on commit c498f71

Please sign in to comment.