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

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Nov 13 23:18:10 UTC 2018


 loleaflet/js/toolbar.js      |    4 +++-
 loleaflet/js/w2ui-1.5.rc1.js |    3 +++
 loleaflet/src/map/Map.js     |   12 +++++++++++-
 3 files changed, 17 insertions(+), 2 deletions(-)

New commits:
commit 96d1bc34fa30fce6d85c2a39e9896ca8bd3656b9
Author:     Tor Lillqvist <tml at collabora.com>
AuthorDate: Wed Nov 7 16:10:59 2018 +0200
Commit:     Tor Lillqvist <tml at collabora.com>
CommitDate: Wed Nov 14 00:17:49 2018 +0100

    If we have a visible cursor (caret), try to keep that stationary
    
    This fixes at least one visible and annoying behaviour: when you zoom
    in using the plus button, or the View>Zoom In menu entry, the caret
    (text insertion cursor) location typically eventually will move
    outside of the window. Then the window suddenly jumps to another
    position so that the caret is again visible.
    
    After this change, the zooming is much smoother and the caret location
    stays visible all the time.
    
    I could possibly have used the setZoomAround() but found it easier to
    write the code incrementally actually understanding what I was
    doing...
    
    This does not fix the problem when the text insertion cursor is
    already out of view when you start zooming in or out. In that case the
    window still bluntly and unexpectedly jumps to make the location of
    the text insertion cursor visible. In my opinion, it should not. I was
    not able to figure out what causes that.
    
    Change-Id: I594c4815f8fea9ebb43c0cb491d5167e603d724a
    Reviewed-on: https://gerrit.libreoffice.org/63027
    Reviewed-by: Tor Lillqvist <tml at collabora.com>
    Tested-by: Tor Lillqvist <tml at collabora.com>

diff --git a/loleaflet/js/toolbar.js b/loleaflet/js/toolbar.js
index 51b84902c..cbe94ab0b 100644
--- a/loleaflet/js/toolbar.js
+++ b/loleaflet/js/toolbar.js
@@ -82,7 +82,9 @@ function onClick(e, id, item, subItem) {
 		throw new Error('unknown id: ' + id);
 	}
 	var docLayer = map._docLayer;
-	map.focus();
+	if (id !== 'zoomin' && id !== 'zoomout') {
+		map.focus();
+	}
 	if (item.disabled) {
 		return;
 	}
diff --git a/loleaflet/js/w2ui-1.5.rc1.js b/loleaflet/js/w2ui-1.5.rc1.js
index 4178a315c..d272cca02 100644
--- a/loleaflet/js/w2ui-1.5.rc1.js
+++ b/loleaflet/js/w2ui-1.5.rc1.js
@@ -13526,6 +13526,9 @@ var w2prompt = function (label, title, callBack) {
                 // event before
                 var edata = this.trigger({ phase: 'before', type: 'click', target: (id != null ? id : this.name),
                     item: it, object: it, originalEvent: event });
+                if (tmp[0] === 'zoomin' || tmp[0] === 'zoomout') {
+                    return;
+                }
                 if (edata.isCancelled === true) return;
 
                 var btn = '#tb_'+ this.name +'_item_'+ w2utils.escapeId(it.id) +' table.w2ui-button';
diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js
index 63d8fa194..7ed70c2c7 100644
--- a/loleaflet/src/map/Map.js
+++ b/loleaflet/src/map/Map.js
@@ -270,7 +270,17 @@ L.Map = L.Evented.extend({
 			// we want it to be glued to the row/column headers instead of being centered
 			this._docLayer._checkSpreadSheetBounds(zoom);
 		}
-		return this.setView(this.getCenter(), zoom, {zoom: options});
+		var curCenter = this.getCenter();
+		if (this._docLayer && this._docLayer._visibleCursor && this.getBounds().contains(this._docLayer._visibleCursor.getCenter())) {
+			// Calculate new center after zoom. The intent is that the caret
+			// position stays the same.
+			var zoomScale = 1.0 / this.getZoomScale(zoom, this._zoom);
+			var caretPos = this._docLayer._visibleCursor.getCenter();
+			var newCenter = new L.LatLng(curCenter.lat + (caretPos.lat - curCenter.lat) * (1.0 - zoomScale),
+						     curCenter.lng + (caretPos.lng - curCenter.lng) * (1.0 - zoomScale));
+			return this.setView(newCenter, zoom, {zoom: options});
+		}
+		return this.setView(curCenter, zoom, {zoom: options});
 	},
 
 	zoomIn: function (delta, options) {


More information about the Libreoffice-commits mailing list