Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/unix/fcitx5/mozc_response_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class MozcCandidateWord final : public CandidateWord {
mozc_state->SelectCandidate(id_);
}

int32_t getId() const { return id_; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: no "get" in name.


private:
int id_;
MozcEngine *engine_;
Expand Down Expand Up @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think paging will actually create a new candidate list object. I don't know if the candidate id can be used but I think we'd better not relying on that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we figure out how paging key update the cursor?

}

bool usedNextBefore() const override { return true; }
Expand All @@ -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<const MozcCandidateWord &>(candidates->candidate(0));
mozc_state->HighlightCandidate(candidate.getId());
}
}

InputContext *ic_;
MozcEngine *engine_;
std::vector<Text> labels_;
Expand Down
29 changes: 29 additions & 0 deletions src/unix/fcitx5/mozc_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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";
Expand Down
6 changes: 5 additions & 1 deletion src/unix/fcitx5/mozc_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down