Skip to content

Commit 45726eb

Browse files
author
Friedrich W. H. Kossebau
committed
Fix OpMergeParagraph to not remove empty text:p of annotations' text
1 parent b340d2b commit 45726eb

3 files changed

Lines changed: 40 additions & 5 deletions

File tree

ChangeLog.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
# Changes between 0.5.6 and 0.5.7
2+
3+
## WebODF
4+
5+
### Fixes
6+
7+
* Fix breaking all empty annotations on merging the paragraph they are contained in with the one before ([#877](https://github.com/kogmbh/WebODF/pull/877)))
8+
9+
110
# Changes between 0.5.5 and 0.5.6
211

312
## WebODF

webodf/lib/ops/OpMergeParagraph.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* @source: https://github.com/kogmbh/WebODF/
2323
*/
2424

25-
/*global ops, runtime, odf, core, Node*/
25+
/*global ops, runtime, odf, core, Node, NodeFilter*/
2626

2727
/**
2828
* Merges two adjacent paragraphs together into the first paragraph. The destination paragraph
@@ -68,10 +68,13 @@ ops.OpMergeParagraph = function OpMergeParagraph() {
6868
/**
6969
* Returns true if the supplied node is an ODF grouping element with no content
7070
* @param {!Node} element
71-
* @return {!boolean}
71+
* @return {!number}
7272
*/
73-
function isEmptyGroupingElement(element) {
74-
return odfUtils.isGroupingElement(element) && odfUtils.hasNoODFContent(element);
73+
function filterEmptyGroupingElementToRemove(element) {
74+
if (odf.OdfUtils.isInlineRoot(element)) {
75+
return NodeFilter.FILTER_SKIP;
76+
}
77+
return odfUtils.isGroupingElement(element) && odfUtils.hasNoODFContent(element) ? NodeFilter.FILTER_REJECT : NodeFilter.FILTER_ACCEPT;
7578
}
7679

7780
/**
@@ -93,7 +96,7 @@ ops.OpMergeParagraph = function OpMergeParagraph() {
9396
// Empty spans need to be cleaned up on merge, as remove text only removes things that contain text content
9497
// Child is moved across before collapsing so any foreign sub-elements are collapsed up the chain next to
9598
// the destination location
96-
domUtils.removeUnwantedNodes(child, isEmptyGroupingElement);
99+
domUtils.removeUnwantedNodes(child, filterEmptyGroupingElementToRemove);
97100
}
98101
child = source.firstChild;
99102
}

webodf/tests/ops/operationtests.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,29 @@
528528
</ops>
529529
<after><office:text><text:p text:style-name="A">abcdefgh</text:p></office:text></after>
530530
</test>
531+
<test name="MergeParagraphWithEmptyAnnotationText inside">
532+
<before><office:text><text:p text:style-name="A">ab</text:p><text:p text:style-name="B">c<office:annotation office:name="alice_1">
533+
<dc:creator e:memberid="Alice">Alice</dc:creator>
534+
<dc:date>2013-08-05T12:34:07.061Z</dc:date>
535+
<text:list>
536+
<text:list-item>
537+
<text:p></text:p>
538+
</text:list-item>
539+
</text:list>
540+
</office:annotation>d</text:p></office:text></before>
541+
<ops>
542+
<op optype="MergeParagraph" destinationStartPosition="0" sourceStartPosition="3" paragraphStyleName="A"/>
543+
</ops>
544+
<after><office:text><text:p text:style-name="A">abc<office:annotation office:name="alice_1">
545+
<dc:creator e:memberid="Alice">Alice</dc:creator>
546+
<dc:date>2013-08-05T12:34:07.061Z</dc:date>
547+
<text:list>
548+
<text:list-item>
549+
<text:p></text:p>
550+
</text:list-item>
551+
</text:list>
552+
</office:annotation>d</text:p></office:text></after>
553+
</test>
531554
<test name="RemoveAndMerge">
532555
<before><office:text><text:p text:style-name="A">abc<text:span text:style-name="B">d</text:span></text:p><text:p text:style-name="C"><text:span text:style-name="D">efgh</text:span></text:p></office:text></before>
533556
<ops>

0 commit comments

Comments
 (0)