diff --git a/src/rimecandidate.cpp b/src/rimecandidate.cpp index a5160b5..1b7cfe5 100644 --- a/src/rimecandidate.cpp +++ b/src/rimecandidate.cpp @@ -37,6 +37,14 @@ void RimeCandidateWord::select(InputContext *inputContext) const { } } +void RimeCandidateWord::delete_(InputContext *inputContext) const { + if (auto *state = engine_->state(inputContext)) { +#ifndef FCITX_RIME_NO_SELECT_CANDIDATE + state->deleteCandidate(inputContext, idx_, /*global=*/false); +#endif + } +} + #ifndef FCITX_RIME_NO_SELECT_CANDIDATE RimeGlobalCandidateWord::RimeGlobalCandidateWord(RimeEngine *engine, const RimeCandidate &candidate, @@ -54,6 +62,12 @@ void RimeGlobalCandidateWord::select(InputContext *inputContext) const { } } +void RimeGlobalCandidateWord::delete_(InputContext *inputContext) const { + if (auto *state = engine_->state(inputContext)) { + state->deleteCandidate(inputContext, idx_, /*global=*/true); + } +} + #endif RimeCandidateList::RimeCandidateList(RimeEngine *engine, InputContext *ic, diff --git a/src/rimecandidate.h b/src/rimecandidate.h index 10f9b52..97b5ee6 100644 --- a/src/rimecandidate.h +++ b/src/rimecandidate.h @@ -21,6 +21,7 @@ class RimeCandidateWord : public CandidateWord { KeySym sym, int idx); void select(InputContext *inputContext) const override; + void delete_(InputContext *inputContext) const; private: RimeEngine *engine_; @@ -35,6 +36,7 @@ class RimeGlobalCandidateWord : public CandidateWord { int idx); void select(InputContext *inputContext) const override; + void delete_(InputContext *inputContext) const; private: RimeEngine *engine_; diff --git a/src/rimestate.cpp b/src/rimestate.cpp index 8fddcf0..db4d566 100644 --- a/src/rimestate.cpp +++ b/src/rimestate.cpp @@ -212,6 +212,24 @@ void RimeState::selectCandidate(InputContext *inputContext, int idx, } updateUI(inputContext, false); } + +void RimeState::deleteCandidate(InputContext *inputContext, int idx, + bool global) { + auto api = engine_->api(); + if (api->is_maintenance_mode()) { + return; + } + auto session = this->session(); + if (!session) { + return; + } + if (global) { + api->delete_candidate(session, idx); + } else { + api->delete_candidate_on_current_page(session, idx); + } + updateUI(inputContext, false); +} #endif bool RimeState::getStatus( diff --git a/src/rimestate.h b/src/rimestate.h index e3b523e..2309aee 100644 --- a/src/rimestate.h +++ b/src/rimestate.h @@ -29,6 +29,7 @@ class RimeState : public InputContextProperty { void keyEvent(KeyEvent &event); #ifndef FCITX_RIME_NO_SELECT_CANDIDATE void selectCandidate(InputContext *inputContext, int idx, bool global); + void deleteCandidate(InputContext *inputContext, int idx, bool global); #endif bool getStatus(const std::function &); void updatePreedit(InputContext *ic, const RimeContext &context);