loleaflet/src/layer/tile/TileLayer.js | 39 ++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-)
New commits: commit 844a9431c88816ec5588827c248182c0d7d48ebf Author: Dennis Francis <dennis.fran...@collabora.com> AuthorDate: Fri Jun 5 13:48:07 2020 +0530 Commit: Dennis Francis <dennis.fran...@collabora.com> CommitDate: Mon Jul 6 18:55:37 2020 +0200 introduce _getCursorRectangle() and _parseRectangle()... and move the parsing/rectangle calculation code there. Change-Id: Ia24cd5d6931cf970336e3acdcd4a07a6da044068 Reviewed-on: https://gerrit.libreoffice.org/c/online/+/98146 Tested-by: Jenkins Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Dennis Francis <dennis.fran...@collabora.com> diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js index cc9cc8287..64c3d9457 100644 --- a/loleaflet/src/layer/tile/TileLayer.js +++ b/loleaflet/src/layer/tile/TileLayer.js @@ -1249,13 +1249,10 @@ L.TileLayer = L.GridLayer.extend({ var obj = JSON.parse(textMsg); var modifierViewId = parseInt(obj.viewId); this._cursorAtMispelledWord = obj.mispelledWord ? Boolean(parseInt(obj.mispelledWord)).valueOf() : false; - var strTwips = obj.rectangle.match(/\d+/g); - 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 rectangle = this._getCursorRectangle(obj); this._visibleCursor = new L.LatLngBounds( - this._twipsToLatLng(topLeftTwips, this._map.getZoom()), - this._twipsToLatLng(bottomRightTwips, this._map.getZoom())); + this._twipsToLatLng(rectangle.getTopLeft(), this._map.getZoom()), + this._twipsToLatLng(rectangle.getBottomRight(), this._map.getZoom())); var cursorPos = this._visibleCursor.getNorthWest(); var docLayer = this._map._docLayer; if ((docLayer._followEditor || docLayer._followUser) && this._map.lastActionByUser) { @@ -3402,6 +3399,36 @@ L.TileLayer = L.GridLayer.extend({ return this.sheetGeometry.getTileTwipsSheetAreaFromPrint(rectangle); }, + _getCursorRectangle: function (msgObj) { + + if (typeof msgObj !== 'object' || !msgObj.hasOwnProperty('rectangle')) { + console.error('invalid cursor message'); + return undefined; + } + + return this._parseRectangle(msgObj.rectangle); + }, + + _parseRectangle: function (rectString) { + + if (typeof rectString !== 'string') { + console.error('invalid rectangle string'); + return undefined; + } + + var strTwips = rectString.match(/\d+/g); + if (strTwips.length < 4) { + console.error('incomplete rectangle'); + return undefined; + } + + 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); + + return new L.Bounds(topLeftTwips, bottomRightTwips); + }, + _debugGetTimeArray: function() { return {count: 0, ms: 0, best: Number.MAX_SAFE_INTEGER, worst: 0, date: 0}; }, _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits