Skip to content

Commit

Permalink
fix deleting current candidate (#906)
Browse files Browse the repository at this point in the history
  • Loading branch information
eagleoflqj authored Jul 4, 2024
1 parent 3bb4fe9 commit 76dd707
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
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

0 comments on commit 76dd707

Please sign in to comment.