loleaflet: graphic selection can get misplaced if mouse is moved fast

Change-Id: I2c1893110ce76bed2c822c8d1ddd293c8f627307
Reviewed-on: https://gerrit.libreoffice.org/40643
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
Tested-by: Jan Holesovsky <kendy@collabora.com>
This commit is contained in:
Marco Cecchetti 2017-08-01 17:51:27 +02:00 committed by Jan Holesovsky
parent 0bfd359a7c
commit 2916b99535

View file

@ -45,25 +45,27 @@ L.Map.Mouse = L.Handler.extend({
if (docLayer._graphicMarker.isDragged) {
return;
}
if (!docLayer._isEmptyRectangle(docLayer._graphicSelection) &&
docLayer._graphicMarker.getBounds().contains(e.latlng)) {
if (!docLayer._isEmptyRectangle(docLayer._graphicSelection)) {
// if we have a graphic selection and the user clicks inside the rectangle
if (e.type === 'mousedown') {
var isInside = docLayer._graphicMarker.getBounds().contains(e.latlng);
if (e.type === 'mousedown' && isInside) {
this._prevMousePos = e.latlng;
}
else if (e.type === 'mousemove' && this._mouseDown && !this._prevMousePos) {
// if the user started to drag the shape before the selection
// has been drawn
this._prevMousePos = e.latlng;
}
else if (e.type === 'mousemove' && this._prevMousePos) {
// we have a graphic selection and the user started to drag it
var delta = L.latLng(e.latlng.lat - this._prevMousePos.lat, e.latlng.lng - this._prevMousePos.lng);
this._prevMousePos = e.latlng;
var oldSelectionCenter = docLayer._graphicMarker.getBounds().getCenter();
var newSelectionCenter = L.latLng(oldSelectionCenter.lat + delta.lat, oldSelectionCenter.lng + delta.lng);
if (docLayer._graphicMarker.editing) {
docLayer._graphicMarker.editing._move(newSelectionCenter);
else if (e.type === 'mousemove' && this._mouseDown) {
if (!this._prevMousePos && isInside) {
// if the user started to drag the shape before the selection
// has been drawn
this._prevMousePos = e.latlng;
}
else {
// we have a graphic selection and the user started to drag it
var delta = L.latLng(e.latlng.lat - this._prevMousePos.lat, e.latlng.lng - this._prevMousePos.lng);
this._prevMousePos = e.latlng;
var oldSelectionCenter = docLayer._graphicMarker.getBounds().getCenter();
var newSelectionCenter = L.latLng(oldSelectionCenter.lat + delta.lat, oldSelectionCenter.lng + delta.lng);
if (docLayer._graphicMarker.editing) {
docLayer._graphicMarker.editing._move(newSelectionCenter);
}
}
}
else if (e.type === 'mouseup') {