From c587900d9cf3bf7404ba8ddbd59a1cc114e8d92d Mon Sep 17 00:00:00 2001 From: Chen Gong Date: Sat, 16 Feb 2019 22:25:37 +0800 Subject: [PATCH] feat(rime_api): get candidate list from index --- src/rime_api.cc | 13 ++++++++++--- src/rime_api.h | 7 ++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/rime_api.cc b/src/rime_api.cc index 39e8251d5..31df7101b 100644 --- a/src/rime_api.cc +++ b/src/rime_api.cc @@ -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(Service::instance().GetSession(session_id)); @@ -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; @@ -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; } diff --git a/src/rime_api.h b/src/rime_api.h index 2d39d21e7..015ccde5b 100644 --- a/src/rime_api.h +++ b/src/rime_api.h @@ -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 @@ -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