(eww-select-display): Display the correct selected item.
authorLars Magne Ingebrigtsen <larsi@gnus.org>
Wed, 19 Jun 2013 17:34:59 +0000 (19:34 +0200)
committerLars Magne Ingebrigtsen <larsi@gnus.org>
Wed, 19 Jun 2013 17:34:59 +0000 (19:34 +0200)
lisp/ChangeLog
lisp/eww.el

index 8b07fb1..7c5e5eb 100644 (file)
@@ -7,6 +7,7 @@
        (eww-process-text-input): New function to make text input field editing
        work.
        (eww-submit): Rewrite to use the new-style form methods.
+       (eww-select-display): Display the correct selected item.
 
        * shr.el (shr-urlify): Use `keymap' instead of `local-map' so that we
        don't shadow mode-specific bindings.
index 91f0a40..bec2b0d 100644 (file)
@@ -445,6 +445,7 @@ or <a> tag."
     (put-text-property start (point) 'eww-form
                       (list :eww-form eww-form
                             :value value
+                            :type "submit"
                             :name (cdr (assq :name cont))))
     (put-text-property start (point) 'keymap eww-submit-map)
     (insert " ")))
@@ -585,17 +586,18 @@ or <a> tag."
          (nconc menu (list :value
                            (cdr (assq :value (cdr elem))))))
        (let ((display (or (cdr (assq 'text (cdr elem))) "")))
-         (setq max (max max (length display))))
-       (push (list 'item
-                   :value (cdr (assq :value (cdr elem)))
-                   :display display)
-             options)))
+         (setq max (max max (length display)))
+         (push (list 'item
+                     :value (cdr (assq :value (cdr elem)))
+                     :display display)
+               options))))
     (when options
+      (setq options (nreverse options))
       ;; If we have no selected values, default to the first value.
       (unless (plist-get menu :value)
        (nconc menu (list :value (nth 2 (car options)))))
       (nconc menu options)
-      (let ((selected (eww-element-value menu)))
+      (let ((selected (eww-select-display menu)))
        (insert selected
                (make-string (- max (length selected)) ? )))
       (put-text-property start (point) 'eww-form menu)
@@ -603,6 +605,16 @@ or <a> tag."
       (put-text-property start (point) 'keymap eww-select-map)
       (shr-ensure-paragraph))))
 
+(defun eww-select-display (select)
+  (let ((value (plist-get select :value))
+       display)
+    (dolist (elem select)
+      (when (and (consp elem)
+                (eq (car elem) 'item)
+                (equal value (plist-get (cdr elem) :value)))
+       (setq display (plist-get (cdr elem) :display))))
+    display))
+
 (defun eww-click-radio (widget &rest ignore)
   (let ((form (plist-get (cdr widget) :eww-form))
        (name (plist-get (cdr widget) :name)))
@@ -635,8 +647,6 @@ or <a> tag."
 (defun eww-input-value (input)
   (let ((type (plist-get input :type)))
     (cond
-     ((equal type "select")
-      )
      (t
       (let ((value (plist-get input :value)))
        (if (string-match " +" value)
@@ -669,6 +679,7 @@ or <a> tag."
                      (and (not (eq input this-input))
                           (null next-submit)
                           (> input-start (point))))
+             (setq next-submit t)
              (push (cons name (plist-get input :value))
                    values)))
           (t