From e13feae42b0dd06583166fc37a25a33086f776e1 Mon Sep 17 00:00:00 2001 From: groverlynn Date: Sun, 16 Jul 2023 22:35:32 +0200 Subject: [PATCH] Update context.cc --- src/rime/context.cc | 22 ++++++++++++---------- src/rime/context.h | 2 +- test/table_test.cc | 8 +++----- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/rime/context.cc b/src/rime/context.cc index 8a255c4e68..0ecd71b2aa 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 58ea39aa5c..f66d2e9267 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/test/table_test.cc b/test/table_test.cc index d78e02d654..61cc4222f5 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); }