mirror of
https://github.com/webodf/WebODF.git
synced 2026-11-30 16:47:58 +01:00
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:
@@ -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;
|
||||
|
||||
|
||||
@@ -62,6 +62,7 @@
|
||||
"ops.Session"
|
||||
],
|
||||
"gui.AnnotationViewManager": [
|
||||
"gui.Viewport",
|
||||
"odf.OdfContainer",
|
||||
"odf.OdfUtils"
|
||||
],
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user