Subject: bug#49987: 27.2; Let image-dired-mouse-toggle-mark act on active region

From: Peter Münster <[email-masked]>
Date: Tue, 10 Aug 2021 22:27:41 +0200

Hi,

It would be nice, if one can toggle marks of all thumbnails in the
active region.

Here is a patch:

* lisp/image-dired.el (image-dired-mouse-toggle-mark): When region is
active, then toggle marks of all images within.

diff --git a/lisp/image-dired.el b/lisp/image-dired.el
index 2509ecf8f8..8a065f2e6f 100644
--- a/lisp/image-dired.el
+++ b/lisp/image-dired.el
@@ -2311,17 +2311,32 @@ non-nil."
       (image-dired-track-original-file))
   (image-dired-display-thumb-properties))
 
-(defun image-dired-mouse-toggle-mark (event)
-  "Use mouse EVENT to toggle dired mark for thumbnail.
+(defun image-dired-mouse-toggle-mark-1 ()
+  "Toggle dired mark for current thumbnail.
 Track this in associated dired buffer if `image-dired-track-movement' is
 non-nil."
-  (interactive "e")
-  (mouse-set-point event)
-  (goto-char (posn-point (event-end event)))
   (if image-dired-track-movement
       (image-dired-track-original-file))
   (image-dired-toggle-mark-thumb-original-file))
 
+(defun image-dired-mouse-toggle-mark (event)
+  "Use mouse EVENT to toggle dired mark for thumbnail.
+Toggle marks of all thumbnails in region, if it's active.
+Track this in associated dired buffer if `image-dired-track-movement' is
+non-nil."
+  (interactive "e")
+  (if (use-region-p)
+      (let ((end (region-end)))
+        (save-excursion
+          (goto-char (region-beginning))
+          (while (<= (point) end)
+            (when (image-dired-image-at-point-p)
+              (image-dired-mouse-toggle-mark-1))
+            (forward-char))))
+    (mouse-set-point event)
+    (goto-char (posn-point (event-end event)))
+    (image-dired-mouse-toggle-mark-1)))
+
 (defun image-dired-dired-display-properties ()
   "Display properties for dired file in the echo area."
   (interactive)

What do think about that?

-- 
           Peter