Skip to content

Commit

Permalink
feat(rime_api): get candidate list from index
Browse files Browse the repository at this point in the history
  • Loading branch information
lotem committed Feb 19, 2019
1 parent 667da57 commit c587900
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
13 changes: 10 additions & 3 deletions src/rime_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -389,8 +389,9 @@ RIME_API Bool RimeFreeStatus(RimeStatus* status) {

// Accessing candidate list

RIME_API Bool RimeCandidateListBegin(RimeSessionId session_id,
RimeCandidateListIterator* iterator) {
RIME_API Bool RimeCandidateListFromIndex(RimeSessionId session_id,
RimeCandidateListIterator* iterator,
int index) {
if (!iterator)
return False;
an<Session> session(Service::instance().GetSession(session_id));
Expand All @@ -401,10 +402,15 @@ RIME_API Bool RimeCandidateListBegin(RimeSessionId session_id,
return False;
memset(iterator, 0, sizeof(RimeCandidateListIterator));
iterator->ptr = ctx->composition().back().menu.get();
iterator->index = -1;
iterator->index = index - 1;
return True;
}

RIME_API Bool RimeCandidateListBegin(RimeSessionId session_id,
RimeCandidateListIterator* iterator) {
return RimeCandidateListFromIndex(session_id, iterator, 0);
}

RIME_API Bool RimeCandidateListNext(RimeCandidateListIterator* iterator) {
if (!iterator)
return False;
Expand Down Expand Up @@ -1054,6 +1060,7 @@ RIME_API RimeApi* rime_get_api() {
s_api.candidate_list_begin = &RimeCandidateListBegin;
s_api.candidate_list_next = &RimeCandidateListNext;
s_api.candidate_list_end = &RimeCandidateListEnd;
s_api.candidate_list_from_index = &RimeCandidateListFromIndex;
}
return &s_api;
}
7 changes: 6 additions & 1 deletion src/rime_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,12 @@ RIME_API Bool RimeGetStatus(RimeSessionId session_id, RimeStatus* status);
RIME_API Bool RimeFreeStatus(RimeStatus* status);

// Accessing candidate list

RIME_API Bool RimeCandidateListBegin(RimeSessionId session_id, RimeCandidateListIterator* iterator);
RIME_API Bool RimeCandidateListNext(RimeCandidateListIterator* iterator);
RIME_API void RimeCandidateListEnd(RimeCandidateListIterator* iterator);
RIME_API Bool RimeCandidateListFromIndex(RimeSessionId session_id,
RimeCandidateListIterator* iterator,
int index);

// Runtime options

Expand Down Expand Up @@ -518,6 +520,9 @@ typedef struct rime_api_t {
// access config files in user data directory, eg. user.yaml and installation.yaml
Bool (*user_config_open)(const char *config_id, RimeConfig* config);

Bool (*candidate_list_from_index)(RimeSessionId session_id,
RimeCandidateListIterator* iterator,
int index);
} RimeApi;

//! API entry
Expand Down

5 comments on commit c587900

@osfans
Copy link
Contributor

@osfans osfans commented on c587900 Feb 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

讚!還缺一個highlight index的api。

@lotem
Copy link
Member Author

@lotem lotem commented on c587900 Feb 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@osfans 願聞其詳

不熟悉移動設備鍵盤,其實我不太明白這個API用在哪裏

@osfans
Copy link
Contributor

@osfans osfans commented on c587900 Mar 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lotem 不好意思,剛看到,觸摸屏或者鼠標會用到。就跟上下方向鍵的作用類似。

默認的是第一項高亮,
比如長按後面的某個候選後,就會高亮那個候選、切換當前的編碼提示等,但不要上屏,等按空格或者單擊後再上屏。

當然現在也有方法實現:比如長按第三個選項時,可以發兩次下箭頭的按鍵事件。

@lotem
Copy link
Member Author

@lotem lotem commented on c587900 Mar 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@osfans 謝謝,瞭解了。
不過樓主這個API怎麼用,我還是想不到,

@osfans
Copy link
Contributor

@osfans osfans commented on c587900 Mar 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lotem 可以輸入高亮選項的編碼,或者朗讀高亮候選項。
先長按高亮,再回車輸入編碼。或者長按直接輸入那一項的編碼。

Please sign in to comment.