Review-request: Fix copy+paste sections (bug 271029)
Sebastian Sauer
mail at dipe.org
Thu May 26 01:20:35 BST 2011
The problem is that on copy+paste text in Words we create ODF ouf of a
fragment. That fragment can contains SectionEnd's without SectionStart's (or
the other way around which would probably produce invalid XML? That case is
not handled with this patch :-/ ). That results then in an assert. See bug
271029 for more details.
Attached patch fixes the assert with the document attached to the bugreport.
But I am not sure if it's complete cause, as I wrote above, we need to take
also the inverse case into account somehow and I am atm not sure how. Maybe we
can just write endElement()'s till the styleStack isEmpty or so?
diff --git a/libs/kotext/opendocument/KoTextWriter.cpp
b/libs/kotext/opendocument/KoTextWriter.cpp
index a938aa0..b61e0d5 100644
--- a/libs/kotext/opendocument/KoTextWriter.cpp
+++ b/libs/kotext/opendocument/KoTextWriter.cpp
@@ -135,6 +135,7 @@ public:
, splitEndBlockNumber(-1)
, splitRegionOpened(false)
, splitIdCounter(1)
+ , sectionLevel(0)
, deleteMergeRegionOpened(false)
, deleteMergeEndBlockNumber(-1)
{
@@ -208,6 +209,7 @@ public:
int splitEndBlockNumber;
bool splitRegionOpened;
bool splitIdCounter;
+ int sectionLevel;
//For saving of delete-changes that result in a merge between two
elements
bool deleteMergeRegionOpened;
@@ -1676,6 +1678,7 @@ void KoTextWriter::Private::writeBlocks(QTextDocument
*document, int from, int t
QVariant v = format.property(KoParagraphStyle::SectionStart);
KoSection* section = (KoSection*)(v.value<void*>());
if (section) {
+ sectionLevel++;
section->saveOdf(context);
}
}
@@ -1731,7 +1734,8 @@ void KoTextWriter::Private::writeBlocks(QTextDocument
*document, int from, int t
if (format.hasProperty(KoParagraphStyle::SectionEnd)) {
QVariant v = format.property(KoParagraphStyle::SectionEnd);
KoSectionEnd* section = (KoSectionEnd*)(v.value<void*>());
- if (section) {
+ if (section && sectionLevel >= 1) {
+ --sectionLevel;
section->saveOdf(context);
}
}
More information about the calligra-devel
mailing list