-
Notifications
You must be signed in to change notification settings - Fork 574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: delete selected candidate #556
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1051,17 +1051,17 @@ size_t RimeGetCaretPos(RimeSessionId session_id) { | |
return ctx->caret_pos(); | ||
} | ||
|
||
Bool RimeSelectCandidate(RimeSessionId session_id, size_t index) { | ||
static bool do_with_candidate(RimeSessionId session_id, size_t index, bool (Context::* verb)(size_t index)) { | ||
an<Session> session(Service::instance().GetSession(session_id)); | ||
if (!session) | ||
return False; | ||
Context *ctx = session->context(); | ||
if (!ctx) | ||
return False; | ||
return Bool(ctx->Select(index)); | ||
return Bool(ctx->*verb(index)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need a pair of parentheses around the function part |
||
} | ||
|
||
Bool RimeSelectCandidateOnCurrentPage(RimeSessionId session_id, size_t index) { | ||
static bool do_with_candidate_on_current_page(RimeSessionId session_id, size_t index, bool (Context::* verb)(size_t index)) { | ||
an<Session> session(Service::instance().GetSession(session_id)); | ||
if (!session) | ||
return False; | ||
|
@@ -1076,13 +1076,29 @@ Bool RimeSelectCandidateOnCurrentPage(RimeSessionId session_id, size_t index) { | |
return False; | ||
const auto& seg(ctx->composition().back()); | ||
size_t page_start = seg.selected_index / page_size * page_size; | ||
return Bool(ctx->Select(page_start + index)); | ||
return (ctx->*verb)(page_start + index); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Used correctly here. |
||
} | ||
|
||
Bool RimeSelectCandidate(RimeSessionId session_id, size_t index) { | ||
return do_with_candidate(session_id, index, Select); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prefer explicit conversion to the returned C type ( Prefer |
||
} | ||
|
||
Bool RimeSelectCandidateOnCurrentPage(RimeSessionId session_id, size_t index) { | ||
return do_with_candidate_on_current_page(session_id, index, Select); | ||
} | ||
|
||
const char* RimeGetVersion() { | ||
return RIME_VERSION; | ||
} | ||
|
||
Bool RimeDeleteCandidate(RimeSessionId session_id, size_t index) { | ||
return do_with_candidate(session_id, index, DeleteCandidate); | ||
} | ||
|
||
Bool RimeDeleteCandidateOnCurrentPage(RimeSessionId session_id, size_t index) { | ||
return do_with_candidate_on_current_page(session_id, index, DeleteCandidate); | ||
} | ||
|
||
void RimeSetCaretPos(RimeSessionId session_id, size_t caret_pos) { | ||
an<Session> session(Service::instance().GetSession(session_id)); | ||
if (!session) | ||
|
@@ -1170,9 +1186,11 @@ RIME_API RimeApi* rime_get_api() { | |
s_api.get_input = &RimeGetInput; | ||
s_api.get_caret_pos = &RimeGetCaretPos; | ||
s_api.select_candidate = &RimeSelectCandidate; | ||
s_api.delete_candidate = &RimeDeleteCandidate; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional: reorder these to match definition in |
||
s_api.get_version = &RimeGetVersion; | ||
s_api.set_caret_pos = &RimeSetCaretPos; | ||
s_api.select_candidate_on_current_page = &RimeSelectCandidateOnCurrentPage; | ||
s_api.delete_candidate_on_current_page = &RimeDeleteCandidateOnCurrentPage; | ||
s_api.candidate_list_begin = &RimeCandidateListBegin; | ||
s_api.candidate_list_next = &RimeCandidateListNext; | ||
s_api.candidate_list_end = &RimeCandidateListEnd; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -550,6 +550,11 @@ typedef struct rime_api_t { | |
void (*commit_proto)(RimeSessionId session_id, RIME_PROTO_BUILDER* commit_builder); | ||
void (*context_proto)(RimeSessionId session_id, RIME_PROTO_BUILDER* context_builder); | ||
void (*status_proto)(RimeSessionId session_id, RIME_PROTO_BUILDER* status_builder); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Merge conflict. Sync the repo. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sync to latest code. |
||
//! delete a candidate at the given index in candidate list. | ||
Bool (*delete_candidate)(RimeSessionId session_id, size_t index); | ||
//! delete a candidate from current page. | ||
Bool (*delete_candidate_on_current_page)(RimeSessionId session_id, size_t index); | ||
} RimeApi; | ||
|
||
//! API entry | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This memeber function should have a definition in
context.h
, in theprivate:
orpretected:
section.