Skip to content

Commit 3947a38

Browse files
author
Friedrich W. H. Kossebau
committed
Support adding annotations to AnnotationViewManager in batches
1 parent d91660b commit 3947a38

2 files changed

Lines changed: 20 additions & 14 deletions

File tree

webodf/lib/gui/AnnotationViewManager.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -341,26 +341,33 @@ gui.AnnotationViewManager = function AnnotationViewManager(canvas, odfFragment,
341341
this.getMinimumHeightForAnnotationPane = getMinimumHeightForAnnotationPane;
342342

343343
/**
344-
* Adds an annotation to track, and wraps and highlights it
345-
* @param {!odf.AnnotationElement} annotation
344+
* Adds annotations to track, and wraps and highlights them
345+
* @param {!Array.<!odf.AnnotationElement>} annotationElements
346346
* @return {undefined}
347347
*/
348-
function addAnnotation(annotation) {
348+
function addAnnotations(annotationElements) {
349+
if (annotationElements.length === 0) {
350+
return;
351+
}
352+
349353
showAnnotationsPane(true);
350354

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);
355+
annotationElements.forEach(function (annotation) {
356+
// TODO: make use of the fact that current list is already sorted
357+
// instead just iterate over the list until the right index to insert is found
358+
annotations.push(annotation);
359+
360+
wrapAnnotation(annotation);
361+
if (annotation.annotationEndElement) {
362+
highlightAnnotation(annotation);
363+
}
364+
});
354365

355366
sortAnnotations();
356367

357-
wrapAnnotation(annotation);
358-
if (annotation.annotationEndElement) {
359-
highlightAnnotation(annotation);
360-
}
361368
rerenderAnnotations();
362369
}
363-
this.addAnnotation = addAnnotation;
370+
this.addAnnotations = addAnnotations;
364371

365372
/**
366373
* Unhighlights, unwraps, and ejects an annotation from the tracking

webodf/lib/odf/OdfCanvas.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,8 +1054,7 @@
10541054
function modifyAnnotations(odffragment) {
10551055
var annotationNodes = /**@type{!Array.<!odf.AnnotationElement>}*/(domUtils.getElementsByTagNameNS(odffragment, officens, 'annotation'));
10561056

1057-
annotationNodes.forEach(annotationViewManager.addAnnotation);
1058-
annotationViewManager.rerenderAnnotations();
1057+
annotationViewManager.addAnnotations(annotationNodes);
10591058
}
10601059

10611060
/**
@@ -1286,7 +1285,7 @@
12861285
*/
12871286
this.addAnnotation = function (annotation) {
12881287
if (annotationViewManager) {
1289-
annotationViewManager.addAnnotation(annotation);
1288+
annotationViewManager.addAnnotations([annotation]);
12901289
fixContainerSize();
12911290
}
12921291
};

0 commit comments

Comments
 (0)