]> git.eshelyaron.com Git - emacs.git/commitdiff
Minor adjustments to eww text field change handlers
authorPo Lu <luangruo@yahoo.com>
Tue, 30 Apr 2024 05:21:59 +0000 (13:21 +0800)
committerEshel Yaron <me@eshelyaron.com>
Tue, 30 Apr 2024 07:41:14 +0000 (09:41 +0200)
* lisp/net/eww.el (eww-check-text-conversion): Fix doc string.
(eww-mode): Specify face, eww-form and field as nonsticky
properties by default.
(eww-tag-textarea, eww-form-text): Render properties
front-sticky.
(eww-process-text-input): Use field functions to compute field
bounds.

(cherry picked from commit 3555447b7e9b16ddf3b52091a23be1b91155854c)

lisp/net/eww.el

index 5a138dcc46a26a58396cdf494538cd95eaf153f2..c3437ddd1d65d52efb11c28df41a21313c986199 100644 (file)
@@ -1308,7 +1308,7 @@ Set `text-conversion-style' to the value `action' if it isn't
 already and point is within the prompt field, or if
 `text-conversion-style' is `nil', so as to guarantee that
 the input method functions properly for the purpose of typing
-within the ERC prompt."
+within text input fields."
   (when (and (eq major-mode 'eww-mode)
              (fboundp 'set-text-conversion-style))
     (if (eq (car-safe (get-text-property (point) 'field))
@@ -1347,7 +1347,11 @@ within the ERC prompt."
   (setq-local outline-search-function 'shr-outline-search
               outline-level 'shr-outline-level)
   (add-hook 'post-command-hook #'eww-check-text-conversion nil t)
-  (setq buffer-read-only t))
+  (setq buffer-read-only t)
+  ;; Insertion at the first character of a field should inherit the
+  ;; field's face, form and field, not the previous character's.
+  (setq text-property-default-nonsticky '((face . t) (eww-form . t)
+                                          (field . t))))
 
 (defvar text-scale-mode)
 (defvar text-scale-mode-amount)
@@ -1685,6 +1689,7 @@ Interactively, EVENT is the value of `last-nonmenu-event'."
     (put-text-property start (point) readonly-property t)
     (put-text-property start (point) 'eww-form form)
     (put-text-property start (point) 'field form)
+    (put-text-property start (point) 'front-sticky t)
     (insert " ")))
 
 (defconst eww-text-input-types '("text" "password" "textarea"
@@ -1695,13 +1700,7 @@ Interactively, EVENT is the value of `last-nonmenu-event'."
 See URL `https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input'.")
 
 (defun eww-process-text-input (beg end replace-length)
-  (when-let* ((pos (and (< (1+ end) (point-max))
-                       (> (1- end) (point-min))
-                       (cond
-                        ((get-text-property (1+ end) 'eww-form)
-                         (1+ end))
-                        ((get-text-property (1- end) 'eww-form)
-                         (1- end))))))
+  (when-let* ((pos (field-beginning (point))))
     (let* ((form (get-text-property pos 'eww-form))
           (properties (text-properties-at pos))
            (buffer-undo-list t)
@@ -1719,7 +1718,7 @@ See URL `https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input'.")
                 (1- (line-end-position))
               (eww-end-of-field)))
            (while (and (> length 0)
-                       (eql (char-after (1- (point))) ? ))
+                       (eq (char-after (1- (point))) ? ))
              (delete-region (1- (point)) (point))
              (cl-decf length))))
         ((< length 0)
@@ -1743,6 +1742,7 @@ See URL `https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input'.")
          (when (string-match " +\\'" value)
            (setq value (substring value 0 (match-beginning 0))))
          (plist-put form :value value)
+          (plist-put form :type type)
          (when (equal type "password")
            ;; Display passwords as asterisks.
            (let ((start (eww-beginning-of-field)))
@@ -1780,6 +1780,7 @@ See URL `https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input'.")
                     :type "textarea"
                     :name (dom-attr dom 'name)))
     (put-text-property start (point) 'eww-form form)
+    (put-text-property start (point) 'front-sticky t)
     (put-text-property start (point) 'field form)
     (put-text-property start (1+ start) 'shr-tab-stop t)))