sc/source/ui/app/inputhdl.cxx | 20 ++++++++++++++++---- sc/source/ui/inc/inputhdl.hxx | 2 ++ 2 files changed, 18 insertions(+), 4 deletions(-)
New commits: commit 2f6b667ce9bf3d3d1bfd13d25b6c7605fc01577c Author: Eike Rathke <er...@redhat.com> AuthorDate: Tue Jun 21 09:49:31 2022 +0200 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Wed Jun 22 20:43:15 2022 +0200 Resolves: tdf#149589 No "+ or - may start formula" when editing content If it was a formula already it would start with = anyway. Change-Id: Ib3c0ebcaf99231d387f1aace8e1a5642061de3a0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136208 Reviewed-by: Eike Rathke <er...@redhat.com> Tested-by: Jenkins (cherry picked from commit 909cdd552199d35f7c10be0a8be370158aea0815) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136173 Tested-by: Eike Rathke <er...@redhat.com> Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/sc/source/ui/app/inputhdl.cxx b/sc/source/ui/app/inputhdl.cxx index 042fed788ff8..088d3ecfc297 100644 --- a/sc/source/ui/app/inputhdl.cxx +++ b/sc/source/ui/app/inputhdl.cxx @@ -830,6 +830,7 @@ ScInputHandler::ScInputHandler() bLastIsSymbol( false ), mbDocumentDisposing(false), mbPartialPrefix(false), + mbEditingExistingContent(false), nValidation( 0 ), eAttrAdjust( SvxCellHorJustify::Standard ), aScaleX( 1,1 ), @@ -1768,6 +1769,9 @@ void ScInputHandler::LOKPasteFunctionData(const OUString& rFunctionName) if (pEditEngine) { aFormula = pEditEngine->GetText(0); + /* TODO: LOK: are you sure you want '+' and '-' let start formulas with + * function names? That was meant for "data typist" numeric keyboard + * input. */ bEdit = aFormula.getLength() > 1 && (aFormula[0] == '=' || aFormula[0] == '+' || aFormula[0] == '-'); } @@ -2556,6 +2560,7 @@ bool ScInputHandler::StartTable( sal_Unicode cTyped, bool bFromCommand, bool bIn } else aStr = GetEditText(mpEditEngine.get()); + mbEditingExistingContent = !aStr.isEmpty(); if (aStr.startsWith("{=") && aStr.endsWith("}") ) // Matrix formula? { @@ -2570,8 +2575,7 @@ bool ScInputHandler::StartTable( sal_Unicode cTyped, bool bFromCommand, bool bIn if ( bAutoComplete ) GetColData(); - if ( !aStr.isEmpty() && ( aStr[0] == '=' || aStr[0] == '+' || aStr[0] == '-' ) && - !cTyped && !bCreatingFuncView ) + if (!cTyped && !bCreatingFuncView && StartsLikeFormula(aStr)) InitRangeFinder(aStr); // Formula is being edited -> RangeFinder bNewTable = true; // -> PostEditView Call @@ -2762,6 +2766,13 @@ void ScInputHandler::DataChanged( bool bFromTopNotify, bool bSetModified ) bInOwnChange = false; } +bool ScInputHandler::StartsLikeFormula( std::u16string_view rStr ) const +{ + // For new input '+' and '-' may start the dreaded "lazy data typist" + // formula input, editing existing formula content can only start with '='. + return !rStr.empty() && (rStr[0] == '=' || (!mbEditingExistingContent && (rStr[0] == '+' || rStr[0] == '-'))); +} + void ScInputHandler::UpdateFormulaMode() { SfxApplication* pSfxApp = SfxGetpApp(); @@ -2770,8 +2781,7 @@ void ScInputHandler::UpdateFormulaMode() if (bIsFormula) { const OUString& rText = mpEditEngine->GetText(0); - bIsFormula = !rText.isEmpty() && - (rText[0] == '=' || rText[0] == '+' || rText[0] == '-'); + bIsFormula = StartsLikeFormula(rText); } if ( bIsFormula ) @@ -3377,6 +3387,7 @@ void ScInputHandler::EnterHandler( ScEnterMode nBlockMode, bool bBeforeSavingInL nFormSelStart = nFormSelEnd = 0; aFormText.clear(); + mbEditingExistingContent = false; bInOwnChange = false; bInEnterHandler = false; } @@ -3389,6 +3400,7 @@ void ScInputHandler::CancelHandler() bModified = false; mbPartialPrefix = false; + mbEditingExistingContent = false; // Don't rely on ShowRefFrame switching the active view synchronously // execute the function directly on the correct view's bindings instead diff --git a/sc/source/ui/inc/inputhdl.hxx b/sc/source/ui/inc/inputhdl.hxx index f66688a257ca..88ec1dd81adc 100644 --- a/sc/source/ui/inc/inputhdl.hxx +++ b/sc/source/ui/inc/inputhdl.hxx @@ -105,6 +105,7 @@ private: bool mbDocumentDisposing:1; /// To indicate if there is a partial prefix completion. bool mbPartialPrefix:1; + bool mbEditingExistingContent:1; sal_uLong nValidation; SvxCellHorJustify eAttrAdjust; @@ -146,6 +147,7 @@ private: bool StartTable( sal_Unicode cTyped, bool bFromCommand, bool bInputActivated, ScEditEngineDefaulter* pTopEngine ); void RemoveSelection(); + bool StartsLikeFormula( std::u16string_view rStr ) const; void UpdateFormulaMode(); static void InvalidateAttribs(); void ImplCreateEditEngine();