]> git.eshelyaron.com Git - emacs.git/commitdiff
(read-passwd-toggle-visibility): Fix some loose ends
authorStefan Monnier <monnier@iro.umontreal.ca>
Sun, 5 May 2024 14:43:37 +0000 (10:43 -0400)
committerEshel Yaron <me@eshelyaron.com>
Mon, 6 May 2024 16:55:38 +0000 (18:55 +0200)
* lisp/auth-source.el (read-passwd-toggle-visibility): Make sure
we operate on the minibuffer even if some other window was
selected when the little icon was pressed.  Don't hardcode the
keymap representation.  Use the `keymap` property rather than
the `local-map` property so it can't be accidentally shadowed
by something like a minor-mode map.

(cherry picked from commit 61ad641893bc521e98cc06162634299d57b2bf8a)

lisp/auth-source.el

index e6dbead7476d3bc09839e054eaf59099d60da670..2de78c5ae559856ce3d945f7cb1530e16da5cc51 100644 (file)
@@ -2489,22 +2489,30 @@ point is moved into the passwords (see `authinfo-hide-elements').
   "Toggle minibuffer contents visibility.
 Adapt also mode line."
   (interactive)
-  (setq read-passwd--hide-password (not read-passwd--hide-password))
-  (with-current-buffer read-passwd--mode-line-buffer
-    (setq read-passwd--mode-line-icon
-          `(:propertize
-            ,(if icon-preference
-                 (icon-string
-                  (if read-passwd--hide-password
-                      'read-passwd--show-password-icon
-                    'read-passwd--hide-password-icon))
-               "")
-            mouse-face mode-line-highlight
-            local-map
-            (keymap
-             (mode-line keymap (mouse-1 . read-passwd-toggle-visibility)))))
-    (force-mode-line-update))
-  (read-passwd--hide-password))
+  (let ((win (active-minibuffer-window)))
+    (unless win (error "No active minibuffer"))
+    ;; FIXME: In case of a recursive minibuffer, this may select the wrong
+    ;; mini-buffer.
+    (with-current-buffer (window-buffer win)
+      (setq read-passwd--hide-password (not read-passwd--hide-password))
+      (with-current-buffer read-passwd--mode-line-buffer
+        (setq read-passwd--mode-line-icon
+              `(:propertize
+                ,(if icon-preference
+                     (icon-string
+                      (if read-passwd--hide-password
+                          'read-passwd--show-password-icon
+                        'read-passwd--hide-password-icon))
+                   "")
+                mouse-face mode-line-highlight
+                keymap
+                ,(eval-when-compile
+                   (let ((map (make-sparse-keymap)))
+                     (define-key map [mode-line mouse-1]
+                                 #'read-passwd-toggle-visibility)
+                     map))))
+        (force-mode-line-update))
+      (read-passwd--hide-password))))
 
 (defvar read-passwd-map
   ;; BEWARE: `defconst' would purecopy it, breaking the sharing with