[gnome-maps/wip/mlundblad/improve-osm-url-parsing: 2/2] placeEntry: Don't re-trigger place set when set from URL




commit abc6d7707858700c5e586777b6f64019fa264ad2
Author: Marcus Lundblad <ml update uu se>
Date:   Sat Nov 28 23:30:29 2020 +0100

    placeEntry: Don't re-trigger place set when set from URL
    
    When a URL matching coordinates is entered, the entry
    will be re-set to the bare coordinates. In this case
    don't trigger a re-set of the place property, as this
    would overwrite the initial zoom level set from the URL.

 src/placeEntry.js | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
---
diff --git a/src/placeEntry.js b/src/placeEntry.js
index 7be0aa04..732d3f0f 100644
--- a/src/placeEntry.js
+++ b/src/placeEntry.js
@@ -199,6 +199,15 @@ var PlaceEntry = GObject.registerClass({
             return false;
     }
 
+    /**
+     * Returns true if two locations are equal when rounded to displayes
+     * coordinate precision
+     */
+    _roundedLocEquals(locA, locB) {
+        return '%.5f, %.5f'.format(locA.latitude, locA.longitude) ===
+               '%.5f, %.5f'.format(locB.latitude, locB.longitude)
+    }
+
     _parse() {
         let parsed = false;
 
@@ -218,7 +227,14 @@ var PlaceEntry = GObject.registerClass({
 
         let parsedLocation = Place.Place.parseCoordinates(this.text);
         if (parsedLocation) {
-            this.place = new Place.Place({ location: parsedLocation });
+            /* if the place was a parsed OSM coordinate URL, it will have
+             * gotten re-written as bare coordinates and trigger a search-changed,
+             * in this case don't re-set the place, as it will loose the zoom
+             * level from the URL if set
+             */
+            if (!this.place ||
+                !this._roundedLocEquals(parsedLocation, this.place.location))
+                this.place = new Place.Place({ location: parsedLocation });
             parsed = true;
         }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]