Skip to content

Commit

Permalink
try to add delete candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
mokapsing committed Apr 26, 2024
1 parent bfe405a commit 15db5c7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/rimecandidate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/rimecandidate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand All @@ -35,6 +36,7 @@ class RimeGlobalCandidateWord : public CandidateWord {
int idx);

void select(InputContext *inputContext) const override;
void delete_(InputContext *inputContext) const;

private:
RimeEngine *engine_;
Expand Down
18 changes: 18 additions & 0 deletions src/rimestate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions src/rimestate.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(const RimeStatus &)> &);
void updatePreedit(InputContext *ic, const RimeContext &context);
Expand Down

0 comments on commit 15db5c7

Please sign in to comment.