diff options
author | Dennis Francis <dennis.francis@collabora.com> | 2021-05-04 13:28:41 +0530 |
---|---|---|
committer | Dennis Francis <dennis.francis@collabora.com> | 2021-05-13 16:23:21 +0200 |
commit | f8039c6d645acb015a6c4e45000bbfd1311bfea3 (patch) | |
tree | 8680c9cd893a48c89ed40cc276bb4d5d84611a09 /sc | |
parent | e2f771ffe8e82ba5a5001a71601abf3c45c56192 (diff) |
tdf#142214: 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/+/115457
Tested-by: Jenkins
Reviewed-by: Dennis Francis <dennis.francis@collabora.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/source/ui/app/inputhdl.cxx | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx index 9085f28638c3..3082cdb83455 100644 --- a/sc/source/ui/app/inputhdl.cxx +++ b/sc/source/ui/app/inputhdl.cxx @@ -163,10 +163,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 @@ -217,6 +220,8 @@ ScTypedCaseStrSet::const_iterator findTextAll( std::advance(retit, nPos); } ++nCount; + if (nMax > 0 && nCount >= nMax) + break; } } else // Forwards @@ -249,6 +254,8 @@ ScTypedCaseStrSet::const_iterator findTextAll( if ( nCount == 0 ) retit = it; // remember first match iterator ++nCount; + if (nMax > 0 && nCount >= nMax) + break; } } @@ -1963,12 +1970,16 @@ void ScInputHandler::UseColData() // When typing if (aText.isEmpty()) return; + 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) return; + 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 |