Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix deleting current candidate #906

Merged
merged 2 commits into from
Jul 4, 2024
Merged
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
1 change: 0 additions & 1 deletion src/rime/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <list>
#include <map>
#include <memory>
#include <optional>
#include <set>
#include <string>
#include <unordered_map>
Expand Down
19 changes: 9 additions & 10 deletions src/rime/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -143,27 +143,26 @@ bool Context::Highlight(size_t index) {
return true;
}

bool Context::DeleteCandidate(std::optional<size_t> index) {
if (composition_.empty())
return false;
Segment& seg(composition_.back());
auto cand = index ? seg.GetCandidateAt(*index) : seg.GetSelectedCandidate();
bool Context::DeleteCandidate(an<Candidate> cand) {
if (!cand)
return false;
DLOG(INFO) << "Deleting candidate: " << cand->text();
if (index) {
seg.selected_index = *index;
}
delete_notifier_(this);
return true; // CAVEAT: this doesn't mean anything is deleted for sure
}

bool Context::DeleteCandidate(size_t index) {
return DeleteCandidate(std::optional{index});
if (composition_.empty())
return false;
Segment& seg(composition_.back());
return DeleteCandidate(seg.GetCandidateAt(index));
}

bool Context::DeleteCurrentSelection() {
return DeleteCandidate({});
if (composition_.empty())
return false;
Segment& seg(composition_.back());
return DeleteCandidate(seg.GetSelectedCandidate());
}

bool Context::ConfirmCurrentSelection() {
Expand Down
2 changes: 1 addition & 1 deletion src/rime/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class RIME_API Context {

private:
string GetSoftCursor() const;
bool DeleteCandidate(std::optional<size_t> index);
bool DeleteCandidate(an<Candidate> cand);

string input_;
size_t caret_pos_ = 0;
Expand Down