Skip to content

Commit

Permalink
im: select n-th candidate when number n is pressed
Browse files Browse the repository at this point in the history
This is the todo list (xdavidwu#1), and I agree it's quite useful.
  • Loading branch information
johnchen902 committed Apr 17, 2021
1 parent 314f87d commit f7cb5eb
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions im.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ static void noop() {

static void vte_hack(struct wlchewing_state *state);

static bool commit_bottom_panel(struct wlchewing_state *state, int offset) {
int index = state->bottom_panel->selected_index + offset;
if (index >= chewing_cand_TotalChoice(state->chewing))
return false;
chewing_cand_choose_by_index(state->chewing, index);
chewing_cand_close(state->chewing);
bottom_panel_destroy(state->bottom_panel);
state->bottom_panel = NULL;
return true;
}

int im_key_press(struct wlchewing_state *state, uint32_t key) {
xkb_keysym_t keysym = xkb_state_key_get_one_sym(state->xkb_state,
key + 8);
Expand Down Expand Up @@ -68,12 +79,15 @@ int im_key_press(struct wlchewing_state *state, uint32_t key) {
switch(keysym){
case XKB_KEY_Return:
case XKB_KEY_KP_Enter:
chewing_cand_choose_by_index(state->chewing,
state->bottom_panel->selected_index);
chewing_cand_close(state->chewing);
bottom_panel_destroy(state->bottom_panel);
state->bottom_panel = NULL;
need_update = true;
need_update = commit_bottom_panel(state, 0);
break;
case XKB_KEY_1 ... XKB_KEY_9:
need_update = commit_bottom_panel(state,
keysym - XKB_KEY_1);
break;
case XKB_KEY_KP_1 ... XKB_KEY_KP_9:
need_update = commit_bottom_panel(state,
keysym - XKB_KEY_KP_1);
break;
case XKB_KEY_Left:
case XKB_KEY_KP_Left:
Expand Down

0 comments on commit f7cb5eb

Please sign in to comment.