diff --git a/src/rime/context.cc b/src/rime/context.cc index 8a255c4e6..0ecd71b2a 100644 --- a/src/rime/context.cc +++ b/src/rime/context.cc @@ -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( @@ -290,4 +292,4 @@ void Context::ClearTransientOptions() { } } -} // namespace rime +} // namespace rime \ No newline at end of file diff --git a/src/rime/context.h b/src/rime/context.h index 58ea39aa5..f66d2e926 100644 --- a/src/rime/context.h +++ b/src/rime/context.h @@ -110,4 +110,4 @@ class Context { } // namespace rime -#endif // RIME_CONTEXT_H_ +#endif // RIME_CONTEXT_H_ \ No newline at end of file diff --git a/src/rime/dict/table.h b/src/rime/dict/table.h index ca85540ee..7db616eff 100644 --- a/src/rime/dict/table.h +++ b/src/rime/dict/table.h @@ -15,21 +15,13 @@ #include #include -#define RIME_TABLE_UNION(U, V, A, a, B, b) \ - struct U { \ - V value; \ - const A& a() const { \ - return *reinterpret_cast(this); \ - } \ - const B& b() const { \ - return *reinterpret_cast(this); \ - } \ - A& a() { \ - return *reinterpret_cast(this); \ - } \ - B& b() { \ - return *reinterpret_cast(this); \ - } \ +#define RIME_TABLE_UNION(U, V, A, a, B, b) \ + struct U { \ + V value; \ + const A& a() const { return *reinterpret_cast(this); } \ + const B& b() const { return *reinterpret_cast(this); } \ + A& a() { return *reinterpret_cast(this); } \ + B& b() { return *reinterpret_cast(this); } \ } namespace rime { @@ -194,4 +186,4 @@ class Table : public MappedFile { } // namespace rime -#endif // RIME_TABLE_H_ +#endif // RIME_TABLE_H_ \ No newline at end of file diff --git a/test/table_test.cc b/test/table_test.cc index d78e02d65..61cc4222f 100644 --- a/test/table_test.cc +++ b/test/table_test.cc @@ -8,7 +8,6 @@ #include #include - class RimeTableTest : public ::testing::Test { public: virtual void SetUp() { @@ -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[]; @@ -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); }