loleaflet/src/layer/tile/TileLayer.js |   38 +++++++++++++++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)

New commits:
commit 32a0646f9239c09a5b4fefa73c196032d917a7b7
Author: Marco Cecchetti <marco.cecche...@collabora.com>
Date:   Tue Apr 3 12:36:24 2018 +0100

    calc: when expanding selection with shift-<cursor>, view never scrolls
    
    Change-Id: Iaea7b53a84210bcdfc180014a7d530b1455949c9
    Reviewed-on: https://gerrit.libreoffice.org/52639
    Reviewed-by: Jan Holesovsky <ke...@collabora.com>
    Tested-by: Jan Holesovsky <ke...@collabora.com>

diff --git a/loleaflet/src/layer/tile/TileLayer.js 
b/loleaflet/src/layer/tile/TileLayer.js
index 330c86c90..28444a7a0 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -1187,15 +1187,49 @@ L.TileLayer = L.GridLayer.extend({
                this._selectionTextContent = textMsg.substr(22);
        },
 
+       _updateScrollOnCellSelection: function (oldSelection, newSelection) {
+               if (this._map._docLayer._docType === 'spreadsheet' && 
oldSelection) {
+                       var mapBounds = this._map.getBounds();
+                       if (!mapBounds.contains(newSelection) && 
!newSelection.equals(oldSelection)) {
+                               var spacingX = 
Math.abs(this._cellCursor.getEast() - this._cellCursor.getWest()) / 4.0;
+                               var spacingY = 
Math.abs((this._cellCursor.getSouth() - this._cellCursor.getNorth())) / 2.0;
+
+                               var scrollX = 0, scrollY = 0;
+                               if (newSelection.getEast() > 
mapBounds.getEast() && newSelection.getEast() > oldSelection.getEast())
+                                       scrollX = newSelection.getEast() - 
mapBounds.getEast() + spacingX;
+                               else if (newSelection.getWest() < 
mapBounds.getWest() && newSelection.getWest() < oldSelection.getWest())
+                                       scrollX = newSelection.getWest() - 
mapBounds.getWest() - spacingX;
+                               if (newSelection.getNorth() > 
mapBounds.getNorth() && newSelection.getNorth() > oldSelection.getNorth())
+                                       scrollY = newSelection.getNorth() - 
mapBounds.getNorth() + spacingY;
+                               else if (newSelection.getSouth() < 
mapBounds.getSouth() && newSelection.getSouth() < oldSelection.getSouth())
+                                       scrollY = newSelection.getSouth() - 
mapBounds.getSouth() - spacingY;
+                               if (scrollX !== 0 || scrollY !== 0) {
+                                       var newCenter = mapBounds.getCenter();
+                                       newCenter.lng += scrollX;
+                                       newCenter.lat += scrollY;
+                                       var center = 
this._map.project(newCenter);
+                                       center = 
center.subtract(this._map.getSize().divideBy(2));
+                                       center.x = Math.round(center.x < 0 ? 0 
: center.x);
+                                       center.y = Math.round(center.y < 0 ? 0 
: center.y);
+                                       this._map.fire('scrollto', {x: 
center.x, y: center.y});
+                               }
+                       }
+               }
+       },
+
        _onTextSelectionEndMsg: function (textMsg) {
                var strTwips = textMsg.match(/\d+/g);
                if (strTwips != null && this._map._permission === 'edit') {
                        var topLeftTwips = new L.Point(parseInt(strTwips[0]), 
parseInt(strTwips[1]));
                        var offset = new L.Point(parseInt(strTwips[2]), 
parseInt(strTwips[3]));
                        var bottomRightTwips = topLeftTwips.add(offset);
+
+                       var oldSelection = this._textSelectionEnd;
                        this._textSelectionEnd = new L.LatLngBounds(
                                                
this._twipsToLatLng(topLeftTwips, this._map.getZoom()),
                                                
this._twipsToLatLng(bottomRightTwips, this._map.getZoom()));
+
+                       this._updateScrollOnCellSelection(oldSelection, 
this._textSelectionEnd);
                }
                else {
                        this._textSelectionEnd = null;
@@ -1208,14 +1242,16 @@ L.TileLayer = L.GridLayer.extend({
                        var topLeftTwips = new L.Point(parseInt(strTwips[0]), 
parseInt(strTwips[1]));
                        var offset = new L.Point(parseInt(strTwips[2]), 
parseInt(strTwips[3]));
                        var bottomRightTwips = topLeftTwips.add(offset);
+                       var oldSelection = this._textSelectionStart;
                        this._textSelectionStart = new L.LatLngBounds(
                                                
this._twipsToLatLng(topLeftTwips, this._map.getZoom()),
                                                
this._twipsToLatLng(bottomRightTwips, this._map.getZoom()));
+
+                       this._updateScrollOnCellSelection(oldSelection, 
this._textSelectionStart);
                }
                else {
                        this._textSelectionStart = null;
                }
-
        },
 
        _onDialogPaintMsg: function(textMsg, img) {
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to