Skip to content

Commit e9b41aa

Browse files
author
Friedrich
committed
Merge pull request #880 from kossebau/improveAnnotationsView
Improve code around annotations a little + bug fixes
2 parents d91660b + a1b32f3 commit e9b41aa

5 files changed

Lines changed: 36 additions & 30 deletions

File tree

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Fixes
66

77
* 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+
* Fix error message popup on deleting an annotation starting at the end of a paragraph or styled range ([#880](https://github.com/kogmbh/WebODF/pull/880)))
89

910
### Improvements
1011

webodf/lib/gui/AnnotationViewManager.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ gui.AnnotationViewManager = function AnnotationViewManager(canvas, odfFragment,
243243
} else {
244244
annotationNote.style.top = '0px';
245245
}
246+
} else {
247+
annotationNote.style.top = '0px';
246248
}
247249

248250
connectorAngular.style.left = connectorHorizontal.getBoundingClientRect().width / zoomLevel + 'px';
@@ -341,26 +343,33 @@ gui.AnnotationViewManager = function AnnotationViewManager(canvas, odfFragment,
341343
this.getMinimumHeightForAnnotationPane = getMinimumHeightForAnnotationPane;
342344

343345
/**
344-
* Adds an annotation to track, and wraps and highlights it
345-
* @param {!odf.AnnotationElement} annotation
346+
* Adds annotations to track, and wraps and highlights them
347+
* @param {!Array.<!odf.AnnotationElement>} annotationElements
346348
* @return {undefined}
347349
*/
348-
function addAnnotation(annotation) {
350+
function addAnnotations(annotationElements) {
351+
if (annotationElements.length === 0) {
352+
return;
353+
}
354+
349355
showAnnotationsPane(true);
350356

351-
// TODO: make use of the fact that current list is already sorted
352-
// instead just iterate over the list until the right index to insert is found
353-
annotations.push(annotation);
357+
annotationElements.forEach(function (annotation) {
358+
// TODO: make use of the fact that current list is already sorted
359+
// instead just iterate over the list until the right index to insert is found
360+
annotations.push(annotation);
361+
362+
wrapAnnotation(annotation);
363+
if (annotation.annotationEndElement) {
364+
highlightAnnotation(annotation);
365+
}
366+
});
354367

355368
sortAnnotations();
356369

357-
wrapAnnotation(annotation);
358-
if (annotation.annotationEndElement) {
359-
highlightAnnotation(annotation);
360-
}
361370
rerenderAnnotations();
362371
}
363-
this.addAnnotation = addAnnotation;
372+
this.addAnnotations = addAnnotations;
364373

365374
/**
366375
* Unhighlights, unwraps, and ejects an annotation from the tracking
@@ -378,6 +387,7 @@ gui.AnnotationViewManager = function AnnotationViewManager(canvas, odfFragment,
378387
showAnnotationsPane(false);
379388
}
380389
}
390+
this.forgetAnnotation = forgetAnnotation;
381391

382392
/**
383393
* Untracks, unwraps, and unhighlights all annotations

webodf/lib/odf/OdfCanvas.js

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,24 +1046,14 @@
10461046
zoomHelper.setZoomableElement(sizer);
10471047
}
10481048

1049-
/**
1050-
* Wraps all annotations and renders them using the Annotation View Manager.
1051-
* @param {!Element} odffragment
1052-
* @return {undefined}
1053-
*/
1054-
function modifyAnnotations(odffragment) {
1055-
var annotationNodes = /**@type{!Array.<!odf.AnnotationElement>}*/(domUtils.getElementsByTagNameNS(odffragment, officens, 'annotation'));
1056-
1057-
annotationNodes.forEach(annotationViewManager.addAnnotation);
1058-
annotationViewManager.rerenderAnnotations();
1059-
}
1060-
10611049
/**
10621050
* This should create an annotations pane if non existent, and then populate it with annotations
10631051
* If annotations are disallowed, it should remove the pane and all annotations
10641052
* @param {!odf.ODFDocumentElement} odfnode
10651053
*/
10661054
function handleAnnotations(odfnode) {
1055+
var annotationNodes;
1056+
10671057
if (allowAnnotations) {
10681058
if (!annotationsPane.parentNode) {
10691059
sizer.appendChild(annotationsPane);
@@ -1072,7 +1062,9 @@
10721062
annotationViewManager.forgetAnnotations();
10731063
}
10741064
annotationViewManager = new gui.AnnotationViewManager(self, odfnode.body, annotationsPane, showAnnotationRemoveButton);
1075-
modifyAnnotations(odfnode.body);
1065+
annotationNodes = /**@type{!Array.<!odf.AnnotationElement>}*/(domUtils.getElementsByTagNameNS(odfnode.body, officens, 'annotation'));
1066+
annotationViewManager.addAnnotations(annotationNodes);
1067+
10761068
fixContainerSize();
10771069
} else {
10781070
if (annotationsPane.parentNode) {
@@ -1286,18 +1278,19 @@
12861278
*/
12871279
this.addAnnotation = function (annotation) {
12881280
if (annotationViewManager) {
1289-
annotationViewManager.addAnnotation(annotation);
1281+
annotationViewManager.addAnnotations([annotation]);
12901282
fixContainerSize();
12911283
}
12921284
};
12931285

12941286
/**
1295-
* Stops annotations and unwraps it
1287+
* Stops an annotation and unwraps it
1288+
* @param {!odf.AnnotationElement} annotation
12961289
* @return {undefined}
12971290
*/
1298-
this.forgetAnnotations = function () {
1291+
this.forgetAnnotation = function (annotation) {
12991292
if (annotationViewManager) {
1300-
annotationViewManager.forgetAnnotations();
1293+
annotationViewManager.forgetAnnotation(annotation);
13011294
fixContainerSize();
13021295
}
13031296
};

webodf/lib/ops/OdtDocument.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
119119
}
120120
initialDoc = rootElement.cloneNode(true);
121121
odfCanvas.refreshAnnotations();
122+
// workaround AnnotationViewManager not fixing up cursor positions after creating the highlighting
123+
self.fixCursorPositions();
122124
return initialDoc;
123125
};
124126

webodf/lib/ops/OpRemoveAnnotation.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ ops.OpRemoveAnnotation = function OpRemoveAnnotation() {
7272
annotationEnd = annotationNode.annotationEndElement;
7373

7474
// Untrack and unwrap annotation
75-
odtDocument.getOdfCanvas().forgetAnnotations();
75+
odtDocument.getOdfCanvas().forgetAnnotation(annotationNode);
7676

7777
/**
7878
* @param {!Node} node
@@ -92,8 +92,8 @@ ops.OpRemoveAnnotation = function OpRemoveAnnotation() {
9292
// The specified position is the first walkable step in the annotation. The position is always just before the first point of change
9393
odtDocument.emit(ops.OdtDocument.signalStepsRemoved, {position: position > 0 ? position - 1 : position});
9494

95+
odtDocument.getOdfCanvas().rerenderAnnotations();
9596
odtDocument.fixCursorPositions();
96-
odtDocument.getOdfCanvas().refreshAnnotations();
9797
return true;
9898
};
9999

0 commit comments

Comments
 (0)