Function: eww--process-text-input
eww--process-text-input is a byte-compiled function defined in
eww.el.gz.
Signature
(eww--process-text-input BEG END REPLACE-LENGTH)
Source Code
;; Defined in /usr/src/emacs/lisp/net/eww.el.gz
(defun eww--process-text-input (beg end replace-length)
(when-let* ((_ (integerp replace-length))
(pos end)
(form (or (get-text-property pos 'eww-form)
(progn
(setq pos (max (point-min) (1- beg)))
(get-text-property pos 'eww-form)))))
(let* ((properties (text-properties-at pos))
(buffer-undo-list t)
(inhibit-read-only t)
(length (- end beg replace-length))
(type (plist-get form :type)))
(when (member type eww-text-input-types)
;; Make sure the new text has the right properties, which also
;; integrates the new text into the "current field".
(set-text-properties beg end properties)
;; FIXME: This tries to preserve the "length" of the input field,
;; but we should try to preserve the *width* instead.
;; FIXME: Maybe instead of inserting/deleting spaces, we should
;; have a single stretch-space character at the end.
(cond
((> length 0)
;; Delete some space at the end.
(save-excursion
(goto-char
(if (equal type "textarea")
(1- (line-end-position))
(eww-end-of-field)))
(while (and (> length 0)
(eq (char-after (1- (point))) ? ))
(delete-region (1- (point)) (point))
(decf length))))
((< length 0)
;; Add padding.
(save-excursion
(goto-char pos)
(let* ((field-length (- (eww-end-of-field)
(eww-beginning-of-field)))
(ideal-length (cdr (assq :length form))))
;; FIXME: This test isn't right for multiline fields.
(when (or (null ideal-length) (> ideal-length field-length))
(goto-char
(if (equal type "textarea")
(1- (line-end-position))
(1+ (eww-end-of-field))))
(let ((start (point)))
(insert (make-string (min (abs length)
(- ideal-length field-length))
? ))
(set-text-properties start (point) properties)))))))
(let ((value (buffer-substring-no-properties
(eww-beginning-of-field)
(eww-end-of-field))))
(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)))
(put-text-property
start (+ start (length value))
'display (make-string (length value) ?*)))))))))