sc/qa/unit/ucalc.cxx | 19 ++++++++++++++++--- sc/source/core/data/column3.cxx | 28 ++++++++++++++++++++-------- 2 files changed, 36 insertions(+), 11 deletions(-)
New commits: commit 7f36c9acc83d5e14a2db053839e0cb9f3968dcb2 Author: Dennis Francis <dennis.fran...@collabora.com> AuthorDate: Fri May 7 16:32:52 2021 +0530 Commit: Dennis Francis <dennis.fran...@collabora.com> CommitDate: Tue May 25 20:39:54 2021 +0200 tdf#142214: autocomplete: do not search across empty blocks Change-Id: Ia5b0be1eed2bf645fa1e53d71abc7b2e67dfaa0a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115458 Tested-by: Jenkins Reviewed-by: Dennis Francis <dennis.fran...@collabora.com> (cherry picked from commit ca2ec443893731093970914feb750b31ea13e47f) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116083 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index 5b339eba8f67..097f15acfad3 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -576,14 +576,22 @@ void Test::testDataEntries() m_pDoc->SetString(ScAddress(0,5,0), "Andy"); m_pDoc->SetString(ScAddress(0,6,0), "Bruce"); m_pDoc->SetString(ScAddress(0,7,0), "Charlie"); + m_pDoc->SetValue(ScAddress(0,8,0), 100); + m_pDoc->SetValue(ScAddress(0,9,0), 200); m_pDoc->SetString(ScAddress(0,10,0), "Andy"); + m_pDoc->SetValue(ScAddress(0,11,0), 1000); std::vector<ScTypedStrData> aEntries; - m_pDoc->GetDataEntries(0, 0, 0, aEntries); // Try at the very top. + m_pDoc->GetDataEntries(0, 0, 0, aEntries); // Try at the top. + std::vector<ScTypedStrData>::const_iterator it = aEntries.begin(); + CPPUNIT_ASSERT_MESSAGE("The entries should be empty.", bool(it == aEntries.end())); + + aEntries.clear(); + m_pDoc->GetDataEntries(0, 4, 0, aEntries); // Try at A5. // Entries are supposed to be sorted in ascending order, and are all unique. CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), aEntries.size()); - std::vector<ScTypedStrData>::const_iterator it = aEntries.begin(); + it = aEntries.begin(); CPPUNIT_ASSERT_EQUAL(OUString("Andy"), it->GetString()); ++it; CPPUNIT_ASSERT_EQUAL(OUString("Bruce"), it->GetString()); @@ -593,7 +601,7 @@ void Test::testDataEntries() CPPUNIT_ASSERT_MESSAGE("The entries should have ended here.", bool(it == aEntries.end())); aEntries.clear(); - m_pDoc->GetDataEntries(0, MAXROW, 0, aEntries); // Try at the very bottom. + m_pDoc->GetDataEntries(0, 12, 0, aEntries); // Try at A13. CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(3), aEntries.size()); // Make sure we get the same set of suggestions. @@ -606,6 +614,11 @@ void Test::testDataEntries() ++it; CPPUNIT_ASSERT_MESSAGE("The entries should have ended here.", bool(it == aEntries.end())); + aEntries.clear(); + m_pDoc->GetDataEntries(0, MAXROW, 0, aEntries); // Try at the bottom. + it = aEntries.begin(); + CPPUNIT_ASSERT_MESSAGE("The entries should be empty.", bool(it == aEntries.end())); + m_pDoc->DeleteTab(0); } diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx index 69213b7fedbc..42acb311312c 100644 --- a/sc/source/core/data/column3.cxx +++ b/sc/source/core/data/column3.cxx @@ -2562,6 +2562,11 @@ public: return (maPos.first->type == sc::element_type_string || maPos.first->type == sc::element_type_edittext); } + bool isEmpty() const + { + return maPos.first->type == sc::element_type_empty; + } + bool prev() { if (!has()) @@ -2569,7 +2574,7 @@ public: // Not in a string block. Move back until we hit a string block. while (!has()) { - if (maPos.first == miBeg) + if (isEmpty() || maPos.first == miBeg) return false; --maPos.first; // move to the preceding block. @@ -2595,6 +2600,10 @@ public: // Move to the last cell of the previous block. --maPos.first; maPos.second = maPos.first->size - 1; + + if (isEmpty()) + return false; + if (has()) break; } @@ -2609,6 +2618,9 @@ public: // Not in a string block. Move forward until we hit a string block. while (!has()) { + if (isEmpty()) + return false; + ++maPos.first; if (maPos.first == miEnd) return false; @@ -2630,6 +2642,10 @@ public: return false; maPos.second = 0; + + if (isEmpty()) + return false; + if (has()) break; } @@ -2671,16 +2687,12 @@ bool ScColumn::GetDataEntries( // going upward and downward directions in parallel. The start position // cell must be skipped. - StrCellIterator aItrUp(maCells, nStartRow, &GetDoc()); + StrCellIterator aItrUp(maCells, nStartRow-1, &GetDoc()); StrCellIterator aItrDown(maCells, nStartRow+1, &GetDoc()); bool bMoveUp = aItrUp.valid(); - if (!bMoveUp) - // Current cell is invalid. - return false; - - // Skip the start position cell. - bMoveUp = aItrUp.prev(); // Find the previous string cell position. + if (bMoveUp && !aItrUp.has()) + bMoveUp = aItrUp.prev(); // Find the previous string cell position. bool bMoveDown = aItrDown.valid(); if (bMoveDown && !aItrDown.has()) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits