tdf#105908: restore previously deleted range references upon undo.

Change-Id: If1932a5eb10da4c50fbcc3329af75f2e7a0a5137
Reviewed-on: https://gerrit.libreoffice.org/35607
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Kohei Yoshida <libreoffice@kohei.us>
This commit is contained in:
Kohei Yoshida 2017-03-22 21:21:31 -04:00 committed by Kohei Yoshida
parent c4c40632f1
commit 749405af4f
5 changed files with 49 additions and 2 deletions

View file

@ -190,6 +190,8 @@ struct ScComplexRefData
@return TRUE if changed. */
bool IncEndRowSticky( SCROW nDelta, const ScAddress& rPos );
bool IsDeleted() const;
#if DEBUG_FORMULA_COMPILER
void Dump( int nIndent = 0 ) const;
#endif

View file

@ -960,10 +960,17 @@ void ScInterpreter::PopSingleRef( ScAddress& rAdr )
break;
case svSingleRef:
{
const ScSingleRefData* pRefData = p->GetSingleRef();
if (pRefData->IsDeleted())
{
SetError( FormulaError::NoRef);
break;
}
SCCOL nCol;
SCROW nRow;
SCTAB nTab;
SingleRefToVars( *p->GetSingleRef(), nCol, nRow, nTab);
SingleRefToVars( *pRefData, nCol, nRow, nTab);
rAdr.Set( nCol, nRow, nTab );
if (!pDok->m_TableOpList.empty())
ReplaceCell( rAdr );
@ -1085,9 +1092,17 @@ void ScInterpreter::PopDoubleRef( ScRange & rRange, short & rParam, size_t & rRe
nGlobalError = pToken->GetError();
break;
case svDoubleRef:
{
--sp;
DoubleRefToRange( *pToken->GetDoubleRef(), rRange);
const ScComplexRefData* pRefData = pToken->GetDoubleRef();
if (pRefData->IsDeleted())
{
SetError( FormulaError::NoRef);
break;
}
DoubleRefToRange( *pRefData, rRange);
break;
}
case svRefList:
{
const ScRefList* pList = pToken->GetRefList();

View file

@ -613,6 +613,9 @@ double ScInterpreter::IterateParameters( ScIterFunc eFunc, bool bTextAsZero )
case svSingleRef :
{
PopSingleRef( aAdr );
if (nGlobalError == FormulaError::NoRef)
return 0.0;
if ( nGlobalError != FormulaError::NONE && ( eFunc == ifCOUNT2 || eFunc == ifCOUNT ||
( mnSubTotalFlags & SubtotalFlags::IgnoreErrVal ) ) )
{
@ -676,6 +679,9 @@ double ScInterpreter::IterateParameters( ScIterFunc eFunc, bool bTextAsZero )
case svRefList :
{
PopDoubleRef( aRange, nParamCount, nRefInList);
if (nGlobalError == FormulaError::NoRef)
return 0.0;
if ( nGlobalError != FormulaError::NONE && ( eFunc == ifCOUNT2 || eFunc == ifCOUNT ||
( mnSubTotalFlags & SubtotalFlags::IgnoreErrVal ) ) )
{

View file

@ -553,6 +553,11 @@ bool ScComplexRefData::IncEndRowSticky( SCROW nDelta, const ScAddress& rPos )
return true;
}
bool ScComplexRefData::IsDeleted() const
{
return Ref1.IsDeleted() || Ref2.IsDeleted();
}
#if DEBUG_FORMULA_COMPILER
void ScComplexRefData::Dump( int nIndent ) const
{

View file

@ -2625,6 +2625,12 @@ void setRefDeleted( ScComplexRefData& rRef, const sc::RefUpdateContext& rCxt )
}
}
void restoreDeletedRef( ScComplexRefData& rRef, const sc::RefUpdateContext& rCxt )
{
restoreDeletedRef(rRef.Ref1, rCxt);
restoreDeletedRef(rRef.Ref2, rCxt);
}
bool shrinkRange( const sc::RefUpdateContext& rCxt, ScRange& rRefRange, const ScRange& rDeletedRange,
const ScComplexRefData& rRef )
{
@ -3000,6 +3006,19 @@ sc::RefUpdateResult ScTokenArray::AdjustReferenceOnShift( const sc::RefUpdateCon
}
}
if (!rCxt.isDeleted() && rRef.IsDeleted())
{
// Check if the token has reference to previously deleted region.
ScRange aCheckRange = rRef.toAbs(aNewPos);
if (aSelectedRange.In(aCheckRange))
{
// This reference was previously in the deleted region. Restore it.
restoreDeletedRef(rRef, rCxt);
aRes.mbValueChanged = true;
break;
}
}
if (rCxt.isInserted())
{
if (expandRange(rCxt, aAbs, aSelectedRange, rRef))