[Libreoffice-commits] online.git: loleaflet/src

Henry Castro hcastro at collabora.com
Sat Mar 18 01:02:31 UTC 2017


 loleaflet/src/layer/AnnotationManager.js    |   44 ++++++++++------------------
 loleaflet/src/layer/tile/WriterTileLayer.js |    2 -
 2 files changed, 17 insertions(+), 29 deletions(-)

New commits:
commit 92a5320694ca13f211f2140d71b0b1736929fcaa
Author: Henry Castro <hcastro at collabora.com>
Date:   Fri Mar 17 21:01:33 2017 -0400

    loleaflet: insert annotation now pops in the cursor position
    
    Change-Id: I6bdfc0cd8a9603cf10685dc5562afd6d81d52162

diff --git a/loleaflet/src/layer/AnnotationManager.js b/loleaflet/src/layer/AnnotationManager.js
index b1f3d955..e6ccf3e9 100644
--- a/loleaflet/src/layer/AnnotationManager.js
+++ b/loleaflet/src/layer/AnnotationManager.js
@@ -5,8 +5,7 @@
 L.AnnotationManager = L.Class.extend({
 	options: {
 		marginX: 50,
-		marginY: 10,
-		offset: 5
+		marginY: 10
 	},
 
 	initialize: function (map) {
@@ -182,18 +181,19 @@ L.AnnotationManager = L.Class.extend({
 		}
 	},
 
-	add: function (comment, edit) {
+	add: function (comment) {
 		var annotation = L.annotation(this._map.options.maxBounds.getSouthEast(), comment).addTo(this._map);
 		this._items.push(annotation);
 		this._items.sort(function(a, b) {
 			return Math.abs(a._data.anchorPos.min.y) - Math.abs(b._data.anchorPos.min.y) ||
 			       Math.abs(a._data.anchorPos.min.x) - Math.abs(b._data.anchorPos.min.x);
 		});
-		if (edit) {
-			annotation.edit();
-			this.select(annotation);
-			annotation.focus();
-		}
+	},
+
+	edit: function (comment) {
+		var annotation = L.annotation(this._map._docLayer._twipsToLatLng(comment.anchorPos.getTopRight()), comment).addTo(this._map);
+		annotation.edit();
+		annotation.focus();
 	},
 
 	modify: function (annotation) {
@@ -210,7 +210,6 @@ L.AnnotationManager = L.Class.extend({
 			}
 		};
 		this._map.sendUnoCommand('.uno:DeleteComment', comment);
-		this._map.removeLayer(this.removeItem(id));
 		this.unselect();
 		this._map.focus();
 	},
@@ -223,7 +222,6 @@ L.AnnotationManager = L.Class.extend({
 			}
 		};
 		this._map.sendUnoCommand('.uno:AcceptTrackedChange', command);
-		this._map.removeLayer(this.removeItem(id));
 		this.unselect();
 		this._map.focus();
 	},
@@ -236,7 +234,6 @@ L.AnnotationManager = L.Class.extend({
 			}
 		};
 		this._map.sendUnoCommand('.uno:RejectTrackedChange', command);
-		this._map.removeLayer(this.removeItem(id));
 		this.unselect();
 		this._map.focus();
 	},
@@ -251,24 +248,12 @@ L.AnnotationManager = L.Class.extend({
 				obj.redline.anchorPos = L.LOUtil.stringToBounds(obj.redline.textRange);
 				obj.redline.trackchange = true;
 				obj.redline.text = obj.redline.comment;
-				this.add(obj.redline, false);
+				this.add(obj.redline);
 				this._map.focus();
 			} else {
-				var added = this.getItem('new');
-				if (added) {
-					delete obj.comment.action;
-					obj.comment.anchorPos = L.LOUtil.stringToBounds(obj.comment.anchorPos);
-					added._data = obj.comment;
-					this._items.sort(function(a, b) {
-						return Math.abs(a._data.anchorPos.min.y) - Math.abs(b._data.anchorPos.min.y) ||
-						       Math.abs(a._data.anchorPos.min.x) - Math.abs(b._data.anchorPos.min.x);
-					});
-					added.update();
-				}
-				else { // annotation is added by some other view
-					this.add(obj.comment, false);
-					this._map.focus();
-				}
+				obj.comment.anchorPos = L.LOUtil.stringToBounds(obj.comment.anchorPos);
+				this.add(obj.comment);
+				this._map.focus();
 			}
 			this.layout();
 		} else if (action === 'Remove') {
@@ -301,7 +286,9 @@ L.AnnotationManager = L.Class.extend({
 
 	_onAnnotationCancel: function (e) {
 		if (e.annotation._data.id === 'new') {
-			this.remove(e.annotation._data.id);
+			this._map.removeLayer(e.annotation);
+		} else {
+			this.layout();
 		}
 		this._map.focus();
 	},
@@ -324,6 +311,7 @@ L.AnnotationManager = L.Class.extend({
 				}
 			};
 			this._map.sendUnoCommand('.uno:InsertAnnotation', comment);
+			this._map.removeLayer(e.annotation);
 		}
 		else if (e.annotation._data.trackchange) {
 			comment = {
diff --git a/loleaflet/src/layer/tile/WriterTileLayer.js b/loleaflet/src/layer/tile/WriterTileLayer.js
index 3cf193a5..7be1d873 100644
--- a/loleaflet/src/layer/tile/WriterTileLayer.js
+++ b/loleaflet/src/layer/tile/WriterTileLayer.js
@@ -11,7 +11,7 @@ L.WriterTileLayer = L.TileLayer.extend({
 				this._latLngToTwips(this._visibleCursor.getNorthEast()));
 		}
 		if (comment.anchorPos) {
-			this._annotations.add(comment, true);
+			this._annotations.edit(comment);
 		}
 	},
 


More information about the Libreoffice-commits mailing list