1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-06 22:41:06 -08:00

Minor adjustments to eww text field change handlers

* 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.
This commit is contained in:
Po Lu 2024-04-30 13:21:59 +08:00
parent 3000edc617
commit 3555447b7e

View 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 already and point is within the prompt field, or if
`text-conversion-style' is `nil', so as to guarantee that `text-conversion-style' is `nil', so as to guarantee that
the input method functions properly for the purpose of typing 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) (when (and (eq major-mode 'eww-mode)
(fboundp 'set-text-conversion-style)) (fboundp 'set-text-conversion-style))
(if (eq (car-safe (get-text-property (point) 'field)) (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 (setq-local outline-search-function 'shr-outline-search
outline-level 'shr-outline-level) outline-level 'shr-outline-level)
(add-hook 'post-command-hook #'eww-check-text-conversion nil t) (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)
(defvar text-scale-mode-amount) (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) readonly-property t)
(put-text-property start (point) 'eww-form form) (put-text-property start (point) 'eww-form form)
(put-text-property start (point) 'field form) (put-text-property start (point) 'field form)
(put-text-property start (point) 'front-sticky t)
(insert " "))) (insert " ")))
(defconst eww-text-input-types '("text" "password" "textarea" (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'.") See URL `https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input'.")
(defun eww-process-text-input (beg end replace-length) (defun eww-process-text-input (beg end replace-length)
(when-let* ((pos (and (< (1+ end) (point-max)) (when-let* ((pos (field-beginning (point))))
(> (1- end) (point-min))
(cond
((get-text-property (1+ end) 'eww-form)
(1+ end))
((get-text-property (1- end) 'eww-form)
(1- end))))))
(let* ((form (get-text-property pos 'eww-form)) (let* ((form (get-text-property pos 'eww-form))
(properties (text-properties-at pos)) (properties (text-properties-at pos))
(buffer-undo-list t) (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)) (1- (line-end-position))
(eww-end-of-field))) (eww-end-of-field)))
(while (and (> length 0) (while (and (> length 0)
(eql (char-after (1- (point))) ? )) (eq (char-after (1- (point))) ? ))
(delete-region (1- (point)) (point)) (delete-region (1- (point)) (point))
(cl-decf length)))) (cl-decf length))))
((< length 0) ((< length 0)
@ -1743,6 +1742,7 @@ See URL `https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input'.")
(when (string-match " +\\'" value) (when (string-match " +\\'" value)
(setq value (substring value 0 (match-beginning 0)))) (setq value (substring value 0 (match-beginning 0))))
(plist-put form :value value) (plist-put form :value value)
(plist-put form :type type)
(when (equal type "password") (when (equal type "password")
;; Display passwords as asterisks. ;; Display passwords as asterisks.
(let ((start (eww-beginning-of-field))) (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" :type "textarea"
:name (dom-attr dom 'name))) :name (dom-attr dom 'name)))
(put-text-property start (point) 'eww-form form) (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 (point) 'field form)
(put-text-property start (1+ start) 'shr-tab-stop t))) (put-text-property start (1+ start) 'shr-tab-stop t)))