Scroll the annotation node into view after creation

Makes annotation insertion feel cleaner as the user can now see the
complete annotation on insertion.

Fixes #486
This commit is contained in:
Philip Peitsch
2014-08-05 21:26:28 +10:00
parent c845342406
commit 9034648042
4 changed files with 20 additions and 6 deletions
+14 -3
View File
@@ -46,6 +46,11 @@ gui.AnnotatableCanvas.prototype.getZoomLevel = function () {"use strict"; };
* @return {Element}
*/
gui.AnnotatableCanvas.prototype.getSizer = function () {"use strict"; };
/**
* @return {!gui.Viewport}
*/
gui.AnnotatableCanvas.prototype.getViewport = function () {"use strict"; };
/*jslint emptyblock:false*/
/**
@@ -75,7 +80,7 @@ gui.AnnotationViewManager = function AnnotationViewManager(canvas, odfFragment,
/**
* Wraps an annotation with various HTML elements for styling, including connectors
* @param {!odf.AnnotationElement} annotation
* @return {undefined}
* @return {!Element}
*/
function wrapAnnotation(annotation) {
var annotationWrapper = doc.createElement('div'),
@@ -102,6 +107,7 @@ gui.AnnotationViewManager = function AnnotationViewManager(canvas, odfFragment,
annotationWrapper.appendChild(annotationNote);
annotationWrapper.appendChild(connectorHorizontal);
annotationWrapper.appendChild(connectorAngular);
return annotationNote;
}
/**
@@ -343,9 +349,11 @@ gui.AnnotationViewManager = function AnnotationViewManager(canvas, odfFragment,
/**
* Adds an annotation to track, and wraps and highlights it
* @param {!odf.AnnotationElement} annotation
* @param {!boolean=} scrollIntoView Scroll the annotation note into view after creation
* @return {undefined}
*/
function addAnnotation(annotation) {
function addAnnotation(annotation, scrollIntoView) {
var annotationNote;
showAnnotationsPane(true);
// TODO: make use of the fact that current list is already sorted
@@ -354,11 +362,14 @@ gui.AnnotationViewManager = function AnnotationViewManager(canvas, odfFragment,
sortAnnotations();
wrapAnnotation(annotation);
annotationNote = wrapAnnotation(annotation);
if (annotation.annotationEndElement) {
highlightAnnotation(annotation);
}
rerenderAnnotations();
if (scrollIntoView === true) {
canvas.getViewport().scrollIntoView(annotationNote.getBoundingClientRect());
}
}
this.addAnnotation = addAnnotation;
+1
View File
@@ -62,6 +62,7 @@
"ops.Session"
],
"gui.AnnotationViewManager": [
"gui.Viewport",
"odf.OdfContainer",
"odf.OdfUtils"
],
+4 -2
View File
@@ -1065,7 +1065,9 @@
function modifyAnnotations(odffragment) {
var annotationNodes = /**@type{!Array.<!odf.AnnotationElement>}*/(domUtils.getElementsByTagNameNS(odffragment, officens, 'annotation'));
annotationNodes.forEach(annotationViewManager.addAnnotation);
annotationNodes.forEach(function(annotation) {
annotationViewManager.addAnnotation(annotation, false);
});
annotationViewManager.rerenderAnnotations();
}
@@ -1296,7 +1298,7 @@
*/
this.addAnnotation = function (annotation) {
if (annotationViewManager) {
annotationViewManager.addAnnotation(annotation);
annotationViewManager.addAnnotation(annotation, true);
fixContainerSize();
}
};
+1 -1
View File
@@ -46,6 +46,7 @@ module.exports = function (config) {
'lib/gui/CommonConstraints.js',
'lib/gui/SessionConstraints.js',
'lib/gui/BlacklistNamespaceNodeFilter.js',
'lib/gui/Viewport.js',
'lib/xmldom/LSSerializerFilter.js',
'lib/odf/OdfNodeFilter.js',
'lib/odf/Namespaces.js',
@@ -55,7 +56,6 @@ module.exports = function (config) {
'lib/odf/OdfContainer.js',
'lib/odf/OdfUtils.js',
'lib/gui/AnnotationViewManager.js',
'lib/gui/Viewport.js',
'lib/gui/SingleScrollViewport.js',
'lib/odf/FontLoader.js',
'lib/odf/Formatting.js',