emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/osm 832bce78f8 72/77: Implement proper map dragging wit


From: ELPA Syncer
Subject: [elpa] externals/osm 832bce78f8 72/77: Implement proper map dragging with the mouse
Date: Mon, 7 Mar 2022 08:58:09 -0500 (EST)

branch: externals/osm
commit 832bce78f8cff93d4c9505ebddd9ac34eb4f44be
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    Implement proper map dragging with the mouse
---
 README.org |  4 +++-
 osm.el     | 18 +++++++++++++-----
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/README.org b/README.org
index 680287f213..0faaa05271 100644
--- a/README.org
+++ b/README.org
@@ -15,7 +15,8 @@
 
 - Parallel fetching of tiles with curl
 - Scrolling in large and small steps
-- Zooming with keys or with mouse click
+- Zooming
+- Mouse support (dragging, clicking)
 - Map scale indicator
 - Jump to coordinate
 - Search for location by name
@@ -71,6 +72,7 @@ Key bindings in =osm-mode= buffer:
 - ~<mouse-2>~: =osm-org-link-click= - Store point as Org link
 - ~<mouse-3>~: =osm-bookmark-set-click= - Store point as bookmark
 - ~<S-mouse-3>~: =osm-bookmark-delete-click= - Delete bookmark at point
+- ~<down-mouse-1>~: =osm-drag= - Drag the map with the mouse
 - ~g~: =osm-goto= - Go to location
 - ~h~: =osm-home= - Go to home location
 - ~s~: =osm-search= - Search for location
diff --git a/osm.el b/osm.el
index baf26a1598..e764cfe937 100644
--- a/osm.el
+++ b/osm.el
@@ -139,7 +139,7 @@ Should be at least 7 days according to the server usage 
policies."
     (define-key map [mouse-2] #'osm-org-link-click)
     (define-key map [mouse-3] #'osm-bookmark-set-click)
     (define-key map [S-mouse-3] #'osm-bookmark-delete-click)
-    (define-key map [drag-mouse-1] #'osm-drag)
+    (define-key map [down-mouse-1] #'osm-drag)
     (define-key map [up] #'osm-up)
     (define-key map [down] #'osm-down)
     (define-key map [left] #'osm-left)
@@ -351,10 +351,18 @@ Should be at least 7 days according to the server usage 
policies."
   "Handle drag EVENT."
   (interactive "@e")
   (pcase-let ((`(,sx . ,sy) (posn-x-y (event-start event)))
-              (`(,ex . ,ey) (posn-x-y (event-end event))))
-    (cl-incf osm--x (- sx ex))
-    (cl-incf osm--y (- sy ey))
-    (osm--update)))
+              (map (make-sparse-keymap)))
+    (cl-incf sx osm--x)
+    (cl-incf sy osm--y)
+    (define-key map [mouse-movement]
+      (lambda (event)
+        (interactive "@e")
+        (pcase-let ((`(,ex . ,ey) (posn-x-y (event-start event))))
+          (setq osm--x (- sx ex)
+                osm--y (- sy ey))
+          (osm--update))))
+    (setq track-mouse 'dragging)
+    (set-transient-map map t (lambda () (setq track-mouse nil)))))
 
 (defun osm-zoom-click (event)
   "Zoom to the location of the click EVENT."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]