diff options
author | Marco Cecchetti <marco.cecchetti@collabora.com> | 2020-02-12 15:01:19 +0100 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2020-05-10 07:38:09 +0200 |
commit | 300bded85303b1821226329d6b985c197e55c68f (patch) | |
tree | 0cfec4211581eee8f88f583f2007aba4983fc97e /sc/source/ui/app | |
parent | 247f92b02072d6ded919b844b5064f43118bc0ab (diff) |
lok: formula bar: send whole function list
Change-Id: Ibbd142652f3190387700f820e56c494b61bfa658
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93341
Tested-by: Jenkins
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'sc/source/ui/app')
-rw-r--r-- | sc/source/ui/app/inputhdl.cxx | 77 |
1 files changed, 66 insertions, 11 deletions
diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx index e0073b6e5a80..d3f8aa8ec392 100644 --- a/sc/source/ui/app/inputhdl.cxx +++ b/sc/source/ui/app/inputhdl.cxx @@ -1314,6 +1314,10 @@ void ScInputHandler::ShowFuncList( const ::std::vector< OUString > & rFuncStrVec { if (rFuncStrVec.size()) { + auto aPos = pFormulaData->begin(); + sal_uInt32 nCurIndex = std::distance(aPos, miAutoPosFormula); + const sal_uInt32 nSize = pFormulaData->size(); + OUString aFuncNameStr; OUString aDescFuncNameStr; OStringBuffer aPayload; @@ -1340,6 +1344,9 @@ void ScInputHandler::ShowFuncList( const ::std::vector< OUString > & rFuncStrVec if ( !ppFDesc->getFunctionName().isEmpty() ) { aPayload.append("{"); + aPayload.append("\"index\": "); + aPayload.append(OString::number(nCurIndex)); + aPayload.append(", "); aPayload.append("\"signature\": \""); aPayload.append(escapeJSON(ppFDesc->getSignature())); aPayload.append("\", "); @@ -1348,6 +1355,9 @@ void ScInputHandler::ShowFuncList( const ::std::vector< OUString > & rFuncStrVec aPayload.append("\"}, "); } } + ++nCurIndex; + if (nCurIndex == nSize) + nCurIndex = 0; } sal_Int32 nLen = aPayload.getLength(); aPayload[nLen - 2] = ' '; @@ -1510,6 +1520,34 @@ void completeFunction( EditView* pView, const OUString& rInsert, bool& rParInser { ESelection aSel = pView->GetSelection(); + bool bNoInitialLetter = false; + OUString aOld = pView->GetEditEngine()->GetText(0); + // in case we want just insert a function and not completing + if ( comphelper::LibreOfficeKit::isActive() ) + { + ESelection aSelRange = aSel; + --aSelRange.nStartPos; + --aSelRange.nEndPos; + pView->SetSelection(aSelRange); + pView->SelectCurrentWord(); + + if ( aOld == "=" ) + { + bNoInitialLetter = true; + aSelRange.nStartPos = 1; + aSelRange.nEndPos = 1; + pView->SetSelection(aSelRange); + } + else if ( pView->GetSelected().startsWith("()") ) + { + bNoInitialLetter = true; + ++aSelRange.nStartPos; + ++aSelRange.nEndPos; + pView->SetSelection(aSelRange); + } + } + + if(!bNoInitialLetter) { const sal_Int32 nMinLen = std::max(aSel.nEndPos - aSel.nStartPos, sal_Int32(1)); // Since transliteration service is used to test for match, the replaced string could be @@ -1543,7 +1581,6 @@ void completeFunction( EditView* pView, const OUString& rInsert, bool& rParInser // Do not insert parentheses after function names if there already are some // (e.g. if the function name was edited). ESelection aWordSel = pView->GetSelection(); - OUString aOld = pView->GetEditEngine()->GetText(0); // aWordSel.EndPos points one behind string if word at end if (aWordSel.nEndPos < aOld.getLength()) @@ -1602,16 +1639,34 @@ void ScInputHandler::PasteFunctionData() void ScInputHandler::LOKPasteFunctionData( sal_uInt32 nIndex ) { - if (pFormulaData && miAutoPosFormula != pFormulaData->end() && nIndex < pFormulaData->size()) - { - auto aPos = pFormulaData->begin(); - sal_uInt32 nCurIndex = std::distance(aPos, miAutoPosFormula); - nIndex += nCurIndex; - if (nIndex >= pFormulaData->size()) - nIndex -= pFormulaData->size(); - std::advance(aPos, nIndex); - miAutoPosFormula = aPos; - PasteFunctionData(); + if (pActiveViewSh && (pTopView || pTableView)) + { + bool bEdit = false; + OUString aFormula; + EditView* pEditView = pTopView ? pTopView : pTableView; + const EditEngine* pEditEngine = pEditView->GetEditEngine(); + if (pEditEngine) + { + aFormula = pEditEngine->GetText(0); + bEdit = aFormula.getLength() > 1 && (aFormula[0] == '=' || aFormula[0] == '+' || aFormula[0] == '-'); + } + + if ( !bEdit ) + { + OUString aNewFormula('='); + if ( aFormula.startsWith("=") ) + aNewFormula = aFormula; + + InputReplaceSelection( aNewFormula ); + } + + if (pFormulaData && nIndex < pFormulaData->size()) + { + auto aPos = pFormulaData->begin(); + std::advance(aPos, nIndex); + miAutoPosFormula = aPos; + PasteFunctionData(); + } } } |