From: Lars Magne Ingebrigtsen Date: Thu, 27 Nov 2014 19:26:24 +0000 (+0100) Subject: (eww-process-text-input): Try to keep track of the size more reliably. X-Git-Tag: emacs-25.0.90~2635^2~287 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=370258f7616887a7a0edddda8a09299897f2df70;p=emacs.git (eww-process-text-input): Try to keep track of the size more reliably. --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a29cad13cc2..3f636698f43 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -27,6 +27,7 @@ the history. (eww-process-text-input): Fix deletion at the start of the field, too. (eww-mode): Revert mistanken removal of `buffer-disable-undo'. + (eww-process-text-input): Try to keep track of the size more reliably. * dom.el (dom-pp): New function. diff --git a/lisp/net/eww.el b/lisp/net/eww.el index 38837675acf..f65403b3622 100644 --- a/lisp/net/eww.el +++ b/lisp/net/eww.el @@ -405,6 +405,7 @@ See the `eww-search-prefix' variable for the search engine used." (forward-line 1))))) (plist-put eww-data :url url) (setq eww-history-position 0) + (eww-size-text-inputs) (eww-update-header-line-format)))) (defun eww-handle-link (dom) @@ -953,7 +954,7 @@ appears in a or tag." "List of input types which represent a text input. See URL `https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input'.") -(defun eww-process-text-input (beg end length) +(defun eww-process-text-input (beg end replace-length) (when-let (pos (and (< (1+ end) (point-max)) (> (1- end) (point-min)) (cond @@ -964,24 +965,23 @@ See URL `https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input'.") (let* ((form (get-text-property pos 'eww-form)) (properties (text-properties-at pos)) (inhibit-read-only t) + (length (- end beg replace-length)) (type (plist-get form :type))) (when (and form (member type eww-text-input-types)) (cond - ((zerop length) + ((> length 0) ;; Delete some space at the end. (save-excursion (goto-char (if (equal type "textarea") (1- (line-end-position)) (eww-end-of-field))) - (let ((new (- end beg))) - (while (and (> new 0) - (eql (following-char) ? )) - (delete-region (point) (1+ (point))) - (setq new (1- new)))) - (set-text-properties beg end properties))) - ((> length 0) + (while (and (> length 0) + (eql (following-char) ? )) + (delete-region (1- (point)) (point)) + (cl-decf length)))) + ((< length 0) ;; Add padding. (save-excursion (goto-char (1- end)) @@ -990,8 +990,11 @@ See URL `https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input'.") (1- (line-end-position)) (1+ (eww-end-of-field)))) (let ((start (point))) - (insert (make-string length ? )) - (set-text-properties start (point) properties))))) + (insert (make-string (abs length) ? )) + (set-text-properties start (point) properties)) + (goto-char (1- end))))) + (set-text-properties (plist-get form :start) (plist-get form :end) + properties) (let ((value (buffer-substring-no-properties (eww-beginning-of-field) (eww-end-of-field)))) @@ -1190,6 +1193,19 @@ See URL `https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input'.") (setq start (next-single-property-change start 'eww-form)))) (nreverse inputs))) +(defun eww-size-text-inputs () + (let ((start (point-min))) + (while (and start + (< start (point-max))) + (when (or (get-text-property start 'eww-form) + (setq start (next-single-property-change start 'eww-form))) + (let ((props (get-text-property start 'eww-form))) + (plist-put props :start (set-marker (make-marker) start)) + (setq start (next-single-property-change + start 'eww-form nil (point-max))) + (plist-put props + :end (set-marker (make-marker) start))))))) + (defun eww-input-value (input) (let ((type (plist-get input :type)) (value (plist-get input :value)))