summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJustin Luth <justin_luth@sil.org>2017-01-07 16:53:44 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2017-05-26 13:04:10 +0200
commitdae134cd793b96126aab4029f1ea83faf51d4f58 (patch)
tree58586251c252f6122b2edbdf2f4a26b812250fff
parent4dc3e7d5e9044be66177e467d739bd8be7556783 (diff)
tdf#74177 Writer table: refresh formula without losing comments
The presence of an annotation anchor was causing number replacement to fail in Writer's table cells. The formula's value was not recognized as a replaceable number, so the originally computed value remained in the cell, regardless of whether the formula's value changed. Allowing the value to change needs to avoid losing the comments, so the majority of this fix is to preserve the comments. This is not recognized as "fixed" during document loading since the table/formulas are not refreshed at load time. Only documents saved with incorrect results will notice this, and any cursor access inside the table will cause a refresh. Printing also causes a refresh (but not print preview or PDF export). So this patch only fixes document creation or modification, which should be adequate for this bug. Change-Id: I6f11d62c2d56e6b0f6a37371dd5aaef28d525e25 Reviewed-on: https://gerrit.libreoffice.org/32910 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
-rw-r--r--sw/source/core/table/swtable.cxx27
1 files changed, 24 insertions, 3 deletions
diff --git a/sw/source/core/table/swtable.cxx b/sw/source/core/table/swtable.cxx
index 96d58d982162..d122f66fc4e9 100644
--- a/sw/source/core/table/swtable.cxx
+++ b/sw/source/core/table/swtable.cxx
@@ -2016,17 +2016,18 @@ void ChgTextToNum( SwTableBox& rBox, const OUString& rText, const Color* pCol,
if( pTNd->GetText() != rText )
{
- // Exchange text. Bugfix to keep Tabs (front and back!)
+ // Exchange text. Bugfix to keep Tabs (front and back!) and annotations (inword comment anchors)
const OUString& rOrig = pTNd->GetText();
sal_Int32 n;
- for( n = 0; n < rOrig.getLength() && '\x9' == rOrig[n]; ++n )
+ for( n = 0; n < rOrig.getLength() && ('\x9' == rOrig[n] || CH_TXTATR_INWORD == rOrig[n]); ++n )
;
for( ; n < rOrig.getLength() && '\x01' == rOrig[n]; ++n )
;
SwIndex aIdx( pTNd, n );
- for( n = rOrig.getLength(); n && '\x9' == rOrig[--n]; )
+ for( n = rOrig.getLength(); n && ('\x9' == rOrig[--n] || CH_TXTATR_INWORD == rOrig[n]); )
;
+ sal_Int32 nEndPos = n;
n -= aIdx.GetIndex() - 1;
// Reset DontExpand-Flags before exchange, to retrigger expansion
@@ -2041,6 +2042,22 @@ void ChgTextToNum( SwTableBox& rBox, const OUString& rText, const Color* pCol,
pDoc->getIDocumentRedlineAccess().DeleteRedline(aTemp, true, USHRT_MAX);
}
+ // preserve comments inside of the number by deleting number portions starting from the back
+ sal_Int32 nCommentPos = pTNd->GetText().lastIndexOf( CH_TXTATR_INWORD, nEndPos );
+ while( nCommentPos > aIdx.GetIndex() )
+ {
+ pTNd->EraseText( SwIndex(pTNd, nCommentPos+1), nEndPos - nCommentPos, SwInsertFlags::EMPTYEXPAND );
+ // find the next non-sequential comment anchor
+ do
+ {
+ nEndPos = nCommentPos;
+ n = nEndPos - aIdx.GetIndex();
+ nCommentPos = pTNd->GetText().lastIndexOf( CH_TXTATR_INWORD, nEndPos );
+ --nEndPos;
+ }
+ while( nCommentPos > aIdx.GetIndex() && nCommentPos == nEndPos );
+ }
+
pTNd->EraseText( aIdx, n, SwInsertFlags::EMPTYEXPAND );
pTNd->InsertText( rText, aIdx, SwInsertFlags::EMPTYEXPAND );
@@ -2491,6 +2508,10 @@ sal_uLong SwTableBox::IsValidNumTextNd( bool bCheckAttr ) const
continue;
}
}
+ else if( RES_TXTATR_ANNOTATION == pAttr->Which() )
+ {
+ continue;
+ }
nPos = ULONG_MAX;
break;
}