Skip to content

Commit

Permalink
partially implement BulkCursor (fcitx#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj authored and fxliang committed Nov 22, 2024
1 parent 57a1c78 commit 357da0f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ if (NOT DEFINED RIME_TARGET)
set(RIME_TARGET PkgConfig::Rime)
endif()

if ("${Rime_VERSION}" VERSION_LESS "1.10.0")
add_definitions(-DFCITX_RIME_NO_HIGHLIGHT_CANDIDATE)
endif()
if ("${Rime_VERSION}" VERSION_LESS "1.8.0")
add_definitions(-DFCITX_RIME_NO_DELETE_CANDIDATE)
endif()
Expand Down
18 changes: 18 additions & 0 deletions src/rimecandidate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ RimeCandidateList::RimeCandidateList(RimeEngine *engine, InputContext *ic,
setPageable(this);
setBulk(this);
setActionable(this);
#ifndef FCITX_RIME_NO_HIGHLIGHT_CANDIDATE
setBulkCursor(this);
#endif

const auto &menu = context.menu;

Expand Down Expand Up @@ -187,4 +190,19 @@ void RimeCandidateList::triggerAction(const CandidateWord &candidate, int id) {
}
}
}

#ifndef FCITX_RIME_NO_HIGHLIGHT_CANDIDATE
int RimeCandidateList::globalCursorIndex() const {
return -1; // No API available.
}

void RimeCandidateList::setGlobalCursorIndex(int index) {
auto session = engine_->state(ic_)->session(false);
if (!session) {
return;
}
auto *api = engine_->api();
api->highlight_candidate(session, index);
}
#endif
} // namespace fcitx
9 changes: 9 additions & 0 deletions src/rimecandidate.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class RimeCandidateList final : public CandidateList,
,
public BulkCandidateList
#endif
#ifndef FCITX_RIME_NO_HIGHLIGHT_CANDIDATE
,
public BulkCursorCandidateList
#endif
{
public:
RimeCandidateList(RimeEngine *engine, InputContext *ic,
Expand Down Expand Up @@ -94,6 +98,11 @@ class RimeCandidateList final : public CandidateList,
int totalSize() const override;
#endif

#ifndef FCITX_RIME_NO_HIGHLIGHT_CANDIDATE
int globalCursorIndex() const override;
void setGlobalCursorIndex(int index) override;
#endif

bool hasAction(const CandidateWord &candidate) const override;
std::vector<CandidateAction>
candidateActions(const CandidateWord &candidate) const override;
Expand Down

0 comments on commit 357da0f

Please sign in to comment.