Skip to content

Commit

Permalink
Update context.cc
Browse files Browse the repository at this point in the history
  • Loading branch information
groverlynn committed Jul 17, 2023
1 parent a0578f9 commit 74d5dfd
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 32 deletions.
22 changes: 12 additions & 10 deletions src/rime/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,17 @@ void Context::Clear() {
}

bool Context::Select(size_t index) {
bool result = Peek(index);
if (result)
composition_.back().status = Segment::kSelected;
select_notifier_(this);
return result;
}
DLOG(INFO) << "Selection changed from: " << previous_index
<< " to: " << new_index;
return true;
if (composition_.empty())
return false;
Segment& seg(composition_.back());
if (auto cand = seg.GetCandidateAt(index)) {
seg.selected_index = index;
seg.status = Segment::kSelected;
DLOG(INFO) << "Selected: '" << cand->text() << "', index = " << index;
select_notifier_(this);
return true;
}
return false;
}

bool Context::DeleteCandidate(
Expand Down Expand Up @@ -290,4 +292,4 @@ void Context::ClearTransientOptions() {
}
}

} // namespace rime
} // namespace rime
2 changes: 1 addition & 1 deletion src/rime/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,4 @@ class Context {

} // namespace rime

#endif // RIME_CONTEXT_H_
#endif // RIME_CONTEXT_H_
24 changes: 8 additions & 16 deletions src/rime/dict/table.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,13 @@
#include <rime/dict/vocabulary.h>
#include <rime/dict/string_table.h>

#define RIME_TABLE_UNION(U, V, A, a, B, b) \
struct U { \
V value; \
const A& a() const { \
return *reinterpret_cast<const A*>(this); \
} \
const B& b() const { \
return *reinterpret_cast<const B*>(this); \
} \
A& a() { \
return *reinterpret_cast<A*>(this); \
} \
B& b() { \
return *reinterpret_cast<B*>(this); \
} \
#define RIME_TABLE_UNION(U, V, A, a, B, b) \
struct U { \
V value; \
const A& a() const { return *reinterpret_cast<const A*>(this); } \
const B& b() const { return *reinterpret_cast<const B*>(this); } \
A& a() { return *reinterpret_cast<A*>(this); } \
B& b() { return *reinterpret_cast<B*>(this); } \
}

namespace rime {
Expand Down Expand Up @@ -194,4 +186,4 @@ class Table : public MappedFile {

} // namespace rime

#endif // RIME_TABLE_H_
#endif // RIME_TABLE_H_
8 changes: 3 additions & 5 deletions test/table_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <rime/algo/syllabifier.h>
#include <rime/dict/table.h>


class RimeTableTest : public ::testing::Test {
public:
virtual void SetUp() {
Expand All @@ -23,9 +22,8 @@ class RimeTableTest : public ::testing::Test {
}
table_->Load();
}
virtual void TearDown() {
table_->Close();
}
virtual void TearDown() { table_->Close(); }

protected:
static const int total_num_entries = 8;
static const char file_name[];
Expand Down Expand Up @@ -92,7 +90,7 @@ void RimeTableTest::PrepareSampleVocabulary(rime::Syllabary& syll,
d->code.resize(3);
d->code.push_back(2);
d->code.push_back(1);
d->text = "yi-er-san-er-yi";
d->text = "yi-er-san-er-yi";
(*lv4)[-1].entries.push_back(d);
}

Expand Down

0 comments on commit 74d5dfd

Please sign in to comment.