loleaflet/src/layer/tile/TileLayer.js |   88 +++++++++++++++++++---------------
 1 file changed, 50 insertions(+), 38 deletions(-)

New commits:
commit ed652b6a25ca613d2155b320db1deec476d96119
Author:     Pranam Lashkari <lpra...@collabora.com>
AuthorDate: Tue Jul 21 13:59:27 2020 +0530
Commit:     Tamás Zolnai <tamas.zol...@collabora.com>
CommitDate: Tue Jul 28 13:27:45 2020 +0200

    leaflet: fixed selection handler lagging behind
    
    Change-Id: Ic89a6827bac4511a8f9cd9afbcc2594cdc2046f3
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/97897
    Tested-by: Jenkins
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Tested-by: Tamás Zolnai <tamas.zol...@collabora.com>
    Reviewed-by: Tamás Zolnai <tamas.zol...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/99528

diff --git a/loleaflet/src/layer/tile/TileLayer.js 
b/loleaflet/src/layer/tile/TileLayer.js
index 7df2df248..c31d2a896 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -1810,6 +1810,7 @@ L.TileLayer = L.GridLayer.extend({
                                                
this._twipsToLatLng(bottomRightTwips, this._map.getZoom()));
 
                        this._updateScrollOnCellSelection(oldSelection, 
this._textSelectionEnd);
+                       this._updateMarkers();
                }
                else {
                        this._textSelectionEnd = null;
@@ -3133,44 +3134,7 @@ L.TileLayer = L.GridLayer.extend({
                                        
this._isEmptyRectangle(this._textSelectionEnd)) {
                                return;
                        }
-
-                       var startPos = 
this._map.project(this._textSelectionStart.getSouthWest());
-                       var endPos = 
this._map.project(this._textSelectionEnd.getSouthWest());
-                       var startMarkerPos = 
this._map.project(startMarker.getLatLng());
-                       if (startMarkerPos.distanceTo(endPos) < 
startMarkerPos.distanceTo(startPos) && startMarker._icon && endMarker._icon) {
-                               // if the start marker is actually closer to 
the end of the selection
-                               // reverse icons and markers
-                               L.DomUtil.removeClass(startMarker._icon, 
'leaflet-selection-marker-start');
-                               L.DomUtil.removeClass(endMarker._icon, 
'leaflet-selection-marker-end');
-                               L.DomUtil.addClass(startMarker._icon, 
'leaflet-selection-marker-end');
-                               L.DomUtil.addClass(endMarker._icon, 
'leaflet-selection-marker-start');
-                               var tmp = startMarker;
-                               startMarker = endMarker;
-                               endMarker = tmp;
-                       }
-                       else if (startMarker._icon && endMarker._icon) {
-                               // normal markers and normal icons
-                               L.DomUtil.removeClass(startMarker._icon, 
'leaflet-selection-marker-end');
-                               L.DomUtil.removeClass(endMarker._icon, 
'leaflet-selection-marker-start');
-                               L.DomUtil.addClass(startMarker._icon, 
'leaflet-selection-marker-start');
-                               L.DomUtil.addClass(endMarker._icon, 
'leaflet-selection-marker-end');
-                       }
-
-                       if (!startMarker.isDragged) {
-                               var pos = 
this._map.project(this._textSelectionStart.getSouthWest());
-                               pos = pos.subtract(new L.Point(0, 2));
-                               pos = this._map.unproject(pos);
-                               startMarker.setLatLng(pos);
-                               this._map.addLayer(startMarker);
-                       }
-
-                       if (!endMarker.isDragged) {
-                               pos = 
this._map.project(this._textSelectionEnd.getSouthEast());
-                               pos = pos.subtract(new L.Point(0, 2));
-                               pos = this._map.unproject(pos);
-                               endMarker.setLatLng(pos);
-                               this._map.addLayer(endMarker);
-                       }
+                       this._updateMarkers();
                }
                else {
                        this._textSelectionStart = null;
@@ -3183,6 +3147,54 @@ L.TileLayer = L.GridLayer.extend({
                }
        },
 
+       _updateMarkers: function() {
+               var startMarker, endMarker;
+               for (var key in this._selectionHandles) {
+                       if (key === 'start') {
+                               startMarker = this._selectionHandles[key];
+                       }
+                       else if (key === 'end') {
+                               endMarker = this._selectionHandles[key];
+                       }
+               }
+
+               var startPos = 
this._map.project(this._textSelectionStart.getSouthWest());
+               var endPos = 
this._map.project(this._textSelectionEnd.getSouthWest());
+               var startMarkerPos = this._map.project(startMarker.getLatLng());
+               if (startMarkerPos.distanceTo(endPos) < 
startMarkerPos.distanceTo(startPos) && startMarker._icon && endMarker._icon) {
+                       // if the start marker is actually closer to the end of 
the selection
+                       // reverse icons and markers
+                       L.DomUtil.removeClass(startMarker._icon, 
'leaflet-selection-marker-start');
+                       L.DomUtil.removeClass(endMarker._icon, 
'leaflet-selection-marker-end');
+                       L.DomUtil.addClass(startMarker._icon, 
'leaflet-selection-marker-end');
+                       L.DomUtil.addClass(endMarker._icon, 
'leaflet-selection-marker-start');
+                       var tmp = startMarker;
+                       startMarker = endMarker;
+                       endMarker = tmp;
+               }
+               else if (startMarker._icon && endMarker._icon) {
+                       // normal markers and normal icons
+                       L.DomUtil.removeClass(startMarker._icon, 
'leaflet-selection-marker-end');
+                       L.DomUtil.removeClass(endMarker._icon, 
'leaflet-selection-marker-start');
+                       L.DomUtil.addClass(startMarker._icon, 
'leaflet-selection-marker-start');
+                       L.DomUtil.addClass(endMarker._icon, 
'leaflet-selection-marker-end');
+               }
+
+               if (!startMarker.isDragged) {
+                       var pos = 
this._map.project(this._textSelectionStart.getSouthWest());
+                       pos = this._map.unproject(pos);
+                       startMarker.setLatLng(pos);
+                       this._map.addLayer(startMarker);
+               }
+
+               if (!endMarker.isDragged) {
+                       pos = 
this._map.project(this._textSelectionEnd.getSouthEast());
+                       pos = this._map.unproject(pos);
+                       endMarker.setLatLng(pos);
+                       this._map.addLayer(endMarker);
+               }
+       },
+
        hasGraphicSelection: function() {
                return (this._graphicSelection !== null &&
                        !this._isEmptyRectangle(this._graphicSelection));
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to