sc/inc/typedstrdata.hxx       |   11 ++++++-----
 sc/source/ui/app/inputhdl.cxx |   23 +++++++++++++++++++++++
 2 files changed, 29 insertions(+), 5 deletions(-)

New commits:
commit a141f91037f9cf29822a369261f9e99dffffb964
Author:     Justin Luth <justin_l...@sil.org>
AuthorDate: Tue Dec 7 07:42:52 2021 +0200
Commit:     Eike Rathke <er...@redhat.com>
CommitDate: Mon Dec 13 23:29:58 2021 +0100

    tdf#92010 sc autoFormula: prefer MRU formulas
    
    Prior to 4.3, only MRU formulas were auto-completed.
    Then it changed to suggest all formulas - alphabetically
    for the most part.
    
    That 4.3 commit 5b0b7553241bb5150b12bbf7625b4b0b36970272
    completely removed all reference to MRU.
    But it makes sense to prefer an MRU over a strictly
    alphabetical match.
    
    This patch depends on LO 7.4 patch
    "new ScTypedStrData: typically missed argument in CTOR"
    
    Change-Id: Id5d860d1401693f43833719977d1c1e4c386385c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126499
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>
    Reviewed-by: Eike Rathke <er...@redhat.com>
    (cherry picked from commit b93a6964e0466c1b67d2c233040357a8f6c75214)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126749

diff --git a/sc/inc/typedstrdata.hxx b/sc/inc/typedstrdata.hxx
index 7c7b1c7e45d4..c1a3738ce7fe 100644
--- a/sc/inc/typedstrdata.hxx
+++ b/sc/inc/typedstrdata.hxx
@@ -17,11 +17,12 @@ class ScTypedStrData
 {
 public:
     enum StringType {
-        Value    = 0,
-        Standard = 1,
-        Name     = 2,
-        DbName   = 3,
-        Header   = 4
+        Value,
+        MRU,
+        Standard,
+        Name,
+        DbName,
+        Header
     };
 
     ScTypedStrData( const OUString& rStr, double fVal = 0.0, double fRVal = 
0.0, StringType eType = Standard,
diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx
index b9ee0d62d02b..307f0f7a6886 100644
--- a/sc/source/ui/app/inputhdl.cxx
+++ b/sc/source/ui/app/inputhdl.cxx
@@ -1048,6 +1048,29 @@ void ScInputHandler::GetFormulaData()
             pFormulaDataPara->insert(ScTypedStrData(aEntry, 0.0, 0.0, 
ScTypedStrData::Standard));
         }
     }
+
+    // Increase suggestion priority of MRU formulas
+    const ScAppOptions& rOpt = SC_MOD()->GetAppOptions();
+    const sal_uInt16 nMRUCount = rOpt.GetLRUFuncListCount();
+    const sal_uInt16* pMRUList = rOpt.GetLRUFuncList();
+    for (sal_uInt16 i = 0; i < nMRUCount; i++)
+    {
+        const sal_uInt16 nId = pMRUList[i];
+        for (sal_uInt32 j = 0; j < nListCount; j++)
+        {
+            const ScFuncDesc* pDesc = pFuncList->GetFunction(j);
+            if (pDesc->nFIndex == nId && pDesc->mxFuncName)
+            {
+                const OUString aEntry = *pDesc->mxFuncName + 
aParenthesesReplacement;;
+                const ScTypedStrData aData(aEntry, 0.0, 0.0, 
ScTypedStrData::Standard);
+                auto it = pFormulaData->find(aData);
+                if (it != pFormulaData->end())
+                    pFormulaData->erase(it);
+                pFormulaData->insert(ScTypedStrData(aEntry, 0.0, 0.0, 
ScTypedStrData::MRU));
+                break; // Stop searching
+            }
+        }
+    }
     miAutoPosFormula = pFormulaData->end();
     rDoc.GetFormulaEntries( *pFormulaData );
     rDoc.GetFormulaEntries( *pFormulaDataPara );

Reply via email to