diff --git a/src/unix/fcitx5/mozc_response_parser.cc b/src/unix/fcitx5/mozc_response_parser.cc index e989948ab..e05364907 100644 --- a/src/unix/fcitx5/mozc_response_parser.cc +++ b/src/unix/fcitx5/mozc_response_parser.cc @@ -89,6 +89,8 @@ class MozcCandidateWord final : public CandidateWord { mozc_state->SelectCandidate(id_); } + int32_t getId() const { return id_; } + private: int id_; MozcEngine *engine_; @@ -232,10 +234,12 @@ class MozcCandidateList final : public CandidateList, void prev() override { auto *mozc_state = engine_->mozcState(ic_); mozc_state->Paging(true); + highlightFirstCandidate(mozc_state); } void next() override { auto *mozc_state = engine_->mozcState(ic_); mozc_state->Paging(false); + highlightFirstCandidate(mozc_state); } bool usedNextBefore() const override { return true; } @@ -247,6 +251,15 @@ class MozcCandidateList final : public CandidateList, } } + void highlightFirstCandidate(MozcState *mozc_state) { + auto candidates = ic_->inputPanel().candidateList(); + if (!candidates->empty()) { + const auto &candidate = + dynamic_cast(candidates->candidate(0)); + mozc_state->HighlightCandidate(candidate.getId()); + } + } + InputContext *ic_; MozcEngine *engine_; std::vector labels_; diff --git a/src/unix/fcitx5/mozc_state.cc b/src/unix/fcitx5/mozc_state.cc index a926c8bcb..0537aba20 100644 --- a/src/unix/fcitx5/mozc_state.cc +++ b/src/unix/fcitx5/mozc_state.cc @@ -160,6 +160,17 @@ bool MozcState::TrySendClick(int32_t unique_id, mozc::commands::Output* out, return TrySendRawCommand(command, out, out_error); } +bool MozcState::TrySendHighlight(int32_t unique_id, mozc::commands::Output* out, + std::string* out_error) const { + DCHECK(out); + DCHECK(out_error); + + mozc::commands::SessionCommand command; + command.set_type(mozc::commands::SessionCommand::HIGHLIGHT_CANDIDATE); + command.set_id(unique_id); + return TrySendRawCommand(command, out, out_error); +} + bool MozcState::TrySendCompositionMode(mozc::commands::CompositionMode mode, mozc::commands::Output* out, std::string* out_error) const { @@ -288,6 +299,24 @@ void MozcState::SelectCandidate(int32_t id) { } } +void MozcState::HighlightCandidate(int32_t id) { + if (id == kBadCandidateId) { + LOG(ERROR) << "The highlighted candidate doesn't have unique ID."; + return; + } + MOZC_VLOG(1) << "highlight_candidate, id=" << id; + + std::string error; + mozc::commands::Output raw_response; + if (!TrySendHighlight(id, &raw_response, &error)) { + LOG(ERROR) << "IPC failed. error=" << error; + SetAuxString(error); + DrawAll(); + } else { + ParseResponse(raw_response); + } +} + // This function is called from SCIM framework. void MozcState::Reset() { MOZC_VLOG(1) << "resetim"; diff --git a/src/unix/fcitx5/mozc_state.h b/src/unix/fcitx5/mozc_state.h index 89b1a4082..d3936ac68 100644 --- a/src/unix/fcitx5/mozc_state.h +++ b/src/unix/fcitx5/mozc_state.h @@ -62,7 +62,8 @@ class MozcState : public InputContextProperty { bool ProcessKeyEvent(KeySym sym, uint32_t keycode, KeyStates state, bool layout_is_jp, bool is_key_up); - void SelectCandidate(int idx); + void SelectCandidate(int32_t id); + void HighlightCandidate(int32_t id); void Reset(); void FocusIn(); void FocusOut(const InputContextEvent &event); @@ -119,6 +120,9 @@ class MozcState : public InputContextProperty { bool TrySendClick(int32_t unique_id, mozc::commands::Output *out, std::string *out_error) const; + bool TrySendHighlight(int32_t unique_id, mozc::commands::Output *out, + std::string *out_error) const; + // Sends composition mode to the server. bool TrySendCompositionMode(mozc::commands::CompositionMode mode, mozc::commands::Output *out,