[Top][All Lists]

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

master 3444f39: Use a popup menu for <select>s in eww

From: Lars Ingebrigtsen
Subject: master 3444f39: Use a popup menu for <select>s in eww
Date: Sun, 6 Sep 2020 13:04:09 -0400 (EDT)

branch: master
commit 3444f397c7d20ca59f7b18f6fe95aa79b33727e5
Author: Lars Ingebrigtsen <larsi@gnus.org>
Commit: Lars Ingebrigtsen <larsi@gnus.org>

    Use a popup menu for <select>s in eww
    * lisp/net/eww.el (eww-change-select): Use a popup menu for the
    select (bug#43218).
    (eww--form-items): New utility function.
    (eww-select-map): Allow using a mouse to click on select buttons.
 lisp/net/eww.el | 44 +++++++++++++++++++++++++-------------------
 1 file changed, 25 insertions(+), 19 deletions(-)

diff --git a/lisp/net/eww.el b/lisp/net/eww.el
index b720edc..da71d46 100644
--- a/lisp/net/eww.el
+++ b/lisp/net/eww.el
@@ -1134,6 +1134,8 @@ just re-display the HTML already fetched."
 (defvar eww-select-map
   (let ((map (make-sparse-keymap)))
     (define-key map "\r" 'eww-change-select)
+    (define-key map [follow-link] 'mouse-face)
+    (define-key map [mouse-2] 'eww-change-select)
     (define-key map [(control c) (control c)] 'eww-submit)
@@ -1436,26 +1438,30 @@ See URL 
        (setq display (plist-get (cdr elem) :display))))
-(defun eww-change-select ()
+(defun eww--form-items (form)
+  (cl-loop for elem in form
+           when (and (consp elem)
+                     (eq (car elem) 'item))
+           collect (cdr elem)))
+(defun eww-change-select (event)
   "Change the value of the select drop-down menu under point."
-  (interactive)
-  (let* ((input (get-text-property (point) 'eww-form))
-        (completion-ignore-case t)
-        (options
-         (delq nil
-               (mapcar (lambda (elem)
-                         (and (consp elem)
-                              (eq (car elem) 'item)
-                              (cons (plist-get (cdr elem) :display)
-                                    (plist-get (cdr elem) :value))))
-                       input)))
-        (display (completing-read "Change value: " options nil 'require-match))
-        (inhibit-read-only t))
-    ;; If the user doesn't enter anything, don't change anything.
-    (when (> (length display) 0)
-      (plist-put input :value (cdr (assoc-string display options t)))
-      (goto-char
-       (eww-update-field display)))))
+  (interactive (list last-nonmenu-event))
+  (mouse-set-point event)
+  (let ((input (get-text-property (point) 'eww-form)))
+    (popup-menu
+     (cons
+      "Change Value"
+      (mapcar
+       (lambda (elem)
+         (vector (plist-get elem :display)
+                 (lambda ()
+                   (interactive)
+                   (plist-put input :value (plist-get elem :value))
+                   (goto-char (eww-update-field (plist-get elem :display))))
+                 t))
+       (eww--form-items input)))
+     event)))
 (defun eww-update-field (string &optional offset)
   (unless offset

reply via email to

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