desktop/source/lib/init.cxx               |    6 +++---
 include/LibreOfficeKit/LibreOfficeKit.h   |    2 +-
 include/LibreOfficeKit/LibreOfficeKit.hxx |    4 ++--
 include/vcl/ITiledRenderable.hxx          |    2 +-
 sc/inc/docuno.hxx                         |    2 +-
 sc/source/ui/app/inputhdl.cxx             |   16 ++++++++++------
 sc/source/ui/inc/inputhdl.hxx             |    2 +-
 sc/source/ui/unoobj/docuno.cxx            |    6 +++---
 8 files changed, 22 insertions(+), 18 deletions(-)

New commits:
commit c6a3f51a89449f61ad20a1787c0a3cb41fa91466
Author:     Jan Holesovsky <ke...@collabora.com>
AuthorDate: Thu May 7 15:47:49 2020 +0200
Commit:     Andras Timar <andras.ti...@collabora.com>
CommitDate: Sun May 10 21:43:51 2020 +0200

    formula bar: Change completeFunction() to accept string instead of index.
    
    The 'index' is unsafe, because the set it tries to index can change in
    the meantime.  Instead, use the function name and search for it in the
    set, to get the recent index.
    
    Change-Id: Id2a021c32f421057c87b6f7f4fffcc1c98009acb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93666
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Andras Timar <andras.ti...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93910
    Tested-by: Jenkins

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 1a26cdd20b94..40e3d8b3b6a3 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -1136,7 +1136,7 @@ static size_t 
doc_renderShapeSelection(LibreOfficeKitDocument* pThis, char** pOu
 static void doc_resizeWindow(LibreOfficeKitDocument* pThis, unsigned 
nLOKWindowId,
                              const int nWidth, const int nHeight);
 
-static void doc_completeFunction(LibreOfficeKitDocument* pThis, int nIndex);
+static void doc_completeFunction(LibreOfficeKitDocument* pThis, const char*);
 
 
 static void doc_sendFormFieldEvent(LibreOfficeKitDocument* pThis,
@@ -5405,7 +5405,7 @@ static void doc_resizeWindow(LibreOfficeKitDocument* 
/*pThis*/, unsigned nLOKWin
     pWindow->SetSizePixel(Size(nWidth, nHeight));
 }
 
-static void doc_completeFunction(LibreOfficeKitDocument* pThis, int nIndex)
+static void doc_completeFunction(LibreOfficeKitDocument* pThis, const char* 
pFunctionName)
 {
     SolarMutexGuard aGuard;
     SetLastExceptionMsg();
@@ -5417,7 +5417,7 @@ static void doc_completeFunction(LibreOfficeKitDocument* 
pThis, int nIndex)
         return;
     }
 
-    pDoc->completeFunction(nIndex);
+    pDoc->completeFunction(OUString::fromUtf8(pFunctionName));
 }
 
 
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h 
b/include/LibreOfficeKit/LibreOfficeKit.h
index 309744522004..8b68452697b3 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -437,7 +437,7 @@ struct _LibreOfficeKitDocumentClass
                                 int viewId);
 
     /// @see lok::Document::completeFunction().
-    void (*completeFunction) (LibreOfficeKitDocument* pThis, int nIndex);
+    void (*completeFunction) (LibreOfficeKitDocument* pThis, const char* 
pFunctionName);
 
     /// @see lok::Document::setWindowTextSelection
     void (*setWindowTextSelection) (LibreOfficeKitDocument* pThis,
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx 
b/include/LibreOfficeKit/LibreOfficeKit.hxx
index 37eacdfb3649..c85143821717 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -761,9 +761,9 @@ public:
      *
      * @param nIndex is the index of the selected function
      */
-    void completeFunction(int nIndex)
+    void completeFunction(const char* pFunctionName)
     {
-        mpDoc->pClass->completeFunction(mpDoc, nIndex);
+        mpDoc->pClass->completeFunction(mpDoc, pFunctionName);
     }
 
     /**
diff --git a/include/vcl/ITiledRenderable.hxx b/include/vcl/ITiledRenderable.hxx
index 32192796a08a..9e995216e573 100644
--- a/include/vcl/ITiledRenderable.hxx
+++ b/include/vcl/ITiledRenderable.hxx
@@ -287,7 +287,7 @@ public:
     virtual void moveSelectedParts(int /*nPosition*/, bool /*bDuplicate*/) {}
 
     /// @see lok::Document::completeFunction().
-    virtual void completeFunction(int /*nIndex*/)
+    virtual void completeFunction(const OUString& /*rFunctionName*/)
     {
     }
 
diff --git a/sc/inc/docuno.hxx b/sc/inc/docuno.hxx
index 47757a7503b7..7c9c87a4f109 100644
--- a/sc/inc/docuno.hxx
+++ b/sc/inc/docuno.hxx
@@ -387,7 +387,7 @@ public:
     OUString getPostItsPos() override;
 
     /// @see vcl::ITiledRenderable::completeFunction().
-    virtual void completeFunction(int nIndex) override;
+    virtual void completeFunction(const OUString& rFunctionName) override;
 };
 
 class ScDrawPagesObj final : public cppu::WeakImplHelper<
diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx
index d3f8aa8ec392..83079851a552 100644
--- a/sc/source/ui/app/inputhdl.cxx
+++ b/sc/source/ui/app/inputhdl.cxx
@@ -1637,7 +1637,7 @@ void ScInputHandler::PasteFunctionData()
         pActiveView->ShowCursor();
 }
 
-void ScInputHandler::LOKPasteFunctionData( sal_uInt32 nIndex )
+void ScInputHandler::LOKPasteFunctionData(const OUString& rFunctionName)
 {
     if (pActiveViewSh && (pTopView || pTableView))
     {
@@ -1660,12 +1660,16 @@ void ScInputHandler::LOKPasteFunctionData( sal_uInt32 
nIndex )
             InputReplaceSelection( aNewFormula );
         }
 
-        if (pFormulaData && nIndex < pFormulaData->size())
+        if (pFormulaData)
         {
-            auto aPos = pFormulaData->begin();
-            std::advance(aPos, nIndex);
-            miAutoPosFormula = aPos;
-            PasteFunctionData();
+            OUString aNew;
+            ScTypedCaseStrSet::const_iterator aPos = findText(*pFormulaData, 
pFormulaData->begin(), rFunctionName, aNew, /* backward = */false);
+
+            if (aPos != pFormulaData->end())
+            {
+                miAutoPosFormula = aPos;
+                PasteFunctionData();
+            }
         }
     }
 }
diff --git a/sc/source/ui/inc/inputhdl.hxx b/sc/source/ui/inc/inputhdl.hxx
index c6d681e70e05..a71c810845d4 100644
--- a/sc/source/ui/inc/inputhdl.hxx
+++ b/sc/source/ui/inc/inputhdl.hxx
@@ -288,7 +288,7 @@ public:
                                     long nX1, long nX2, long nY1, long nY2,
                                     long nTab, const Color& rColor );
 
-    void            LOKPasteFunctionData( sal_uInt32 nIndex );
+    void            LOKPasteFunctionData(const OUString& rFunctionName);
 };
 
 //  ScInputHdlState
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index da8394343891..2a4153756eb1 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -1078,13 +1078,13 @@ OUString ScModelObj::getPostItsPos()
     return OUString::fromUtf8(aStream.str().c_str());
 }
 
-void ScModelObj::completeFunction(int nIndex)
+void ScModelObj::completeFunction(const OUString& rFunctionName)
 {
     ScInputHandler* pHdl = SC_MOD()->GetInputHdl();
     if (pHdl)
     {
-        assert(nIndex >= 0);
-        pHdl->LOKPasteFunctionData(nIndex);
+        assert(!rFunctionName.isEmpty());
+        pHdl->LOKPasteFunctionData(rFunctionName);
     }
 }
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to