[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.4' - 2 commits - sc/inc sc/source
Dennis Francis (via logerrit)
logerrit at kemper.freedesktop.org
Thu May 6 09:12:54 UTC 2021
sc/inc/column.hxx | 1
sc/inc/document.hxx | 2
sc/inc/table.hxx | 2
sc/source/core/data/column3.cxx | 108 +++++++++++++++++++++++++++++++++++++++
sc/source/core/data/documen3.cxx | 24 +++++++-
sc/source/core/data/table3.cxx | 5 +
sc/source/ui/app/inputhdl.cxx | 21 +++++--
7 files changed, 156 insertions(+), 7 deletions(-)
New commits:
commit 8a840371f3d02919f743c486f258ef8e4511e231
Author: Dennis Francis <dennis.francis at collabora.com>
AuthorDate: Tue May 4 13:28:41 2021 +0530
Commit: Luboš Luňák <l.lunak at collabora.com>
CommitDate: Thu May 6 11:12:36 2021 +0200
show autocompletion only if there is exactly one match
Picking one from many matches by any logic requires the user to pay
attention to the auto completed match and see if it the one they wanted.
Instead show autocomplete only when there is exactly one match with what
the user has already typed.
Change-Id: If8f7e59fe905d3d472a5a5795f96374ec2d1a6e9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115132
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
Reviewed-by: Luboš Luňák <l.lunak at collabora.com>
diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx
index 1df722b95c9f..1601417a8fc0 100644
--- a/sc/source/ui/app/inputhdl.cxx
+++ b/sc/source/ui/app/inputhdl.cxx
@@ -168,10 +168,13 @@ OUString getExactMatch(const ScTypedCaseStrSet& rDataSet, const OUString& rStrin
ScTypedCaseStrSet::const_iterator findTextAll(
const ScTypedCaseStrSet& rDataSet, ScTypedCaseStrSet::const_iterator const & itPos,
- const OUString& rStart, ::std::vector< OUString > &rResultVec, bool bBack)
+ const OUString& rStart, ::std::vector< OUString > &rResultVec, bool bBack, size_t nMax = 0)
{
rResultVec.clear(); // clear contents
+ if (!rDataSet.size())
+ return rDataSet.end();
+
size_t nCount = 0;
ScTypedCaseStrSet::const_iterator retit;
if ( bBack ) // Backwards
@@ -222,6 +225,8 @@ ScTypedCaseStrSet::const_iterator findTextAll(
std::advance(retit, nPos);
}
++nCount;
+ if (nMax > 0 && nCount >= nMax)
+ break;
}
}
else // Forwards
@@ -254,6 +259,8 @@ ScTypedCaseStrSet::const_iterator findTextAll(
if ( nCount == 0 )
retit = it; // remember first match iterator
++nCount;
+ if (nMax > 0 && nCount >= nMax)
+ break;
}
}
@@ -1940,11 +1947,15 @@ void ScInputHandler::UseColData() // When typing
OUString aText = GetEditText(mpEditEngine.get());
if (!aText.isEmpty())
{
+ std::vector< OUString > aResultVec;
OUString aNew;
miAutoPosColumn = pColumnData->end();
- miAutoPosColumn = findText(*pColumnData, miAutoPosColumn, aText, aNew, false);
- if (miAutoPosColumn != pColumnData->end())
+ miAutoPosColumn = findTextAll(*pColumnData, miAutoPosColumn, aText, aResultVec, false, 2);
+ bool bShowCompletion = (aResultVec.size() == 1);
+ if (bShowCompletion)
{
+ assert(miAutoPosColumn != pColumnData->end());
+ aNew = aResultVec[0];
// Strings can contain line endings (e.g. due to dBase import),
// which would result in multiple paragraphs here, which is not desirable.
//! Then GetExactMatch doesn't work either
commit 31aa470c5691271d5c9f49939f3f64fc29803c5d
Author: Dennis Francis <dennis.francis at collabora.com>
AuthorDate: Mon May 3 16:17:05 2021 +0530
Commit: Luboš Luňák <l.lunak at collabora.com>
CommitDate: Thu May 6 11:12:21 2021 +0200
autocomplete from superblock of str/edittext
Change-Id: Ibf73284971652c5cbd9874d81ded4a1f0cbb4e94
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115131
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
Reviewed-by: Luboš Luňák <l.lunak at collabora.com>
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 64485ccd5f2c..bbf9bce9be73 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -537,6 +537,7 @@ public:
sc::ColumnBlockConstPosition& rBlockPos, SCROW nStartRow, SCROW nEndRow,
ScFilterEntries& rFilterEntries );
+ bool GetStringBlockEntries(SCROW nCursorRow, std::set<ScTypedStrData>& rStrings) const;
bool GetDataEntries( SCROW nRow, std::set<ScTypedStrData>& rStrings, bool bLimit ) const;
void UpdateInsertTabAbs(SCTAB nNewPos);
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 4d385e97d0c9..aefdd253467c 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -2060,6 +2060,8 @@ public:
SCTAB nTab, bool bCaseSens,
ScFilterEntries& rFilterEntries );
+ void GetStringBlockEntries( SCCOL nCursorCol, SCROW nCursorRow, SCTAB nTab,
+ std::vector<ScTypedStrData>& rStrings) const;
void GetDataEntries( SCCOL nCol, SCROW nRow, SCTAB nTab,
std::vector<ScTypedStrData>& rStrings, bool bLimit = false );
void GetFormulaEntries( ScTypedCaseStrSet& rStrings );
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 8fa962081a05..437ee058f640 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -948,6 +948,8 @@ public:
void GetFilterEntries(SCCOL nCol, SCROW nRow1, SCROW nRow2, ScFilterEntries& rFilterEntries );
void GetFilteredFilterEntries(SCCOL nCol, SCROW nRow1, SCROW nRow2, const ScQueryParam& rParam, ScFilterEntries& rFilterEntries );
[[nodiscard]]
+ bool GetStringBlockEntries(SCCOL nCursorCol, SCROW nCursorRow, std::set<ScTypedStrData>& rStrings) const;
+ [[nodiscard]]
bool GetDataEntries(SCCOL nCol, SCROW nRow, std::set<ScTypedStrData>& rStrings, bool bLimit);
bool HasColHeader( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow ) const;
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 90a0dcec43aa..4d21dd698beb 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -2525,6 +2525,7 @@ namespace {
*/
class StrCellIterator
{
+protected:
typedef std::pair<sc::CellStoreType::const_iterator,size_t> PosType;
PosType maPos;
sc::CellStoreType::const_iterator const miBeg;
@@ -2641,6 +2642,113 @@ public:
}
};
+/**
+ * Iterate over only over the super-block of string and edit-text blocks.
+ */
+class StrCellBlockIterator: public StrCellIterator
+{
+public:
+ StrCellBlockIterator(const sc::CellStoreType& rCells, SCROW nStart, const ScDocument* pDoc) :
+ StrCellIterator(rCells, nStart, pDoc)
+ {
+ }
+
+ bool prev()
+ {
+ // Don't go up anymore as we're on non-string block.
+ if (!has())
+ return false;
+
+ // We are in a string block.
+ if (maPos.second > 0)
+ {
+ // Move back one cell in the same block.
+ --maPos.second;
+ }
+ else
+ {
+ if (maPos.first == miBeg)
+ return false;
+
+ // Move to the last cell of the previous block.
+ --maPos.first;
+ maPos.second = maPos.first->size - 1;
+ // Reached non-string block.
+ if (!has())
+ return false;
+ }
+ return true;
+ }
+
+ bool next()
+ {
+ // Don't go down anymore as we're on non-string block.
+ if (!has())
+ return false;
+
+ // We are in a string block.
+ ++maPos.second;
+ if (maPos.second >= maPos.first->size)
+ {
+ // Move to the next block.
+ ++maPos.first;
+ if (maPos.first == miEnd)
+ return false;
+
+ maPos.second = 0;
+ // Reached non-string block.
+ if (!has())
+ return false;
+ }
+ return true;
+ }
+
+};
+
+}
+
+// Get a set of strings from super-block of string and edit-text blocks.
+// This used for computing auto-complete entries in input handler.
+bool ScColumn::GetStringBlockEntries(SCROW nCursorRow, std::set<ScTypedStrData>& rStrings) const
+{
+ // Start at the specified row position, and collect all string values
+ // going upward and downward directions in parallel. The cursor position
+ // cell must be skipped.
+
+ StrCellBlockIterator aItrUp(maCells, nCursorRow-1, GetDoc());
+ StrCellBlockIterator aItrDown(maCells, nCursorRow+1, GetDoc());
+
+ bool bMoveUp = aItrUp.valid() && aItrUp.has();
+ bool bMoveDown = aItrDown.valid() && aItrDown.has();
+ bool bFound = false;
+ OUString aStr;
+
+ while (bMoveUp || bMoveDown)
+ {
+ if (bMoveUp)
+ {
+ aStr = aItrUp.get();
+ if (!aStr.isEmpty())
+ {
+ if (rStrings.insert(ScTypedStrData(aStr)).second)
+ bFound = true;
+ }
+ bMoveUp = aItrUp.prev();
+ }
+
+ if (bMoveDown)
+ {
+ aStr = aItrDown.get();
+ if (!aStr.isEmpty())
+ {
+ if (rStrings.insert(ScTypedStrData(aStr)).second)
+ bFound = true;
+ }
+ bMoveDown = aItrDown.next();
+ }
+ }
+
+ return bFound;
}
// GetDataEntries - Strings from continuous Section around nRow
diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx
index 783bac66f2fd..3a588b81fab7 100644
--- a/sc/source/core/data/documen3.cxx
+++ b/sc/source/core/data/documen3.cxx
@@ -1577,6 +1577,27 @@ void ScDocument::GetFilterEntriesArea(
}
}
+/**
+ * Get entries for computing auto-complete entries in input handler (no numbers/formulas)
+ */
+void ScDocument::GetStringBlockEntries(
+ SCCOL nCursorCol, SCROW nCursorRow, SCTAB nTab,
+ std::vector<ScTypedStrData>& rStrings) const
+{
+ if (!ValidTab(nTab) || nTab >= static_cast<SCTAB>(maTabs.size()))
+ return;
+
+ if (!maTabs[nTab])
+ return;
+
+ std::set<ScTypedStrData> aStrings;
+ if (maTabs[nTab]->GetStringBlockEntries(nCursorCol, nCursorRow, aStrings))
+ {
+ rStrings.insert(rStrings.end(), aStrings.begin(), aStrings.end());
+ sortAndRemoveDuplicates(rStrings, true/*bCaseSens*/);
+ }
+}
+
/**
* Entries for selection list listbox (no numbers/formulas)
*/
@@ -1587,8 +1608,7 @@ void ScDocument::GetDataEntries(
if( !bLimit )
{
/* Try to generate the list from list validation. This part is skipped,
- if bLimit==true, because in that case this function is called to get
- cell values for auto completion on input. */
+ if bLimit==true. */
sal_uInt32 nValidation = GetAttr( nCol, nRow, nTab, ATTR_VALIDDATA )->GetValue();
if( nValidation )
{
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index c27c73fb88e1..926429e90fc1 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -3477,6 +3477,11 @@ void ScTable::GetFilteredFilterEntries(
}
}
+bool ScTable::GetStringBlockEntries(SCCOL nCursorCol, SCROW nCursorRow, std::set<ScTypedStrData>& rStrings) const
+{
+ return aCol[nCursorCol].GetStringBlockEntries(nCursorRow, rStrings);
+}
+
bool ScTable::GetDataEntries(SCCOL nCol, SCROW nRow, std::set<ScTypedStrData>& rStrings, bool bLimit)
{
return aCol[nCol].GetDataEntries( nRow, rStrings, bLimit );
diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx
index e7c68c0ad302..1df722b95c9f 100644
--- a/sc/source/ui/app/inputhdl.cxx
+++ b/sc/source/ui/app/inputhdl.cxx
@@ -1913,8 +1913,8 @@ void ScInputHandler::GetColData()
pColumnData.reset( new ScTypedCaseStrSet );
std::vector<ScTypedStrData> aEntries;
- rDoc.GetDataEntries(
- aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(), aEntries, true);
+ rDoc.GetStringBlockEntries(
+ aCursorPos.Col(), aCursorPos.Row(), aCursorPos.Tab(), aEntries);
if (!aEntries.empty())
pColumnData->insert(aEntries.begin(), aEntries.end());
More information about the Libreoffice-commits
mailing list