]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix EWW <textarea> properties when it's on the same line as other text
authorJim Porter <jporterbugs@gmail.com>
Sun, 20 Jul 2025 19:49:40 +0000 (12:49 -0700)
committerEshel Yaron <me@eshelyaron.com>
Fri, 25 Jul 2025 08:10:43 +0000 (10:10 +0200)
* lisp/net/eww.el (eww-tag-textarea): Set 'start' after ensuring
preceding newline.

* test/lisp/net/eww-tests.el (eww-test/tag/textarea/starts-on-new-line):
New test.

(cherry picked from commit 49376118a1cec24d185fdf1ed2d5bb5bfc116699)

lisp/net/eww.el
test/lisp/net/eww-tests.el

index 5c1c803e6c959997b6a28227790c5ac754267cb8..accd7eec5c379a3495809b6b0eeddbd631fda97c 100644 (file)
@@ -1868,12 +1868,12 @@ See URL `https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input'.")
                'display (make-string (length value) ?*)))))))))
 
 (defun eww-tag-textarea (dom)
-  (let ((start (point))
-        (value (or (dom-text dom) ""))
+  (let ((value (or (dom-text dom) ""))
        (lines (string-to-number (or (dom-attr dom 'rows) "10")))
        (width (string-to-number (or (dom-attr dom 'cols) "10")))
-       end form)
+       start end form)
     (shr-ensure-newline)
+    (setq start (point))
     (insert value)
     (shr-ensure-newline)
     (when (< (count-lines start (point)) lines)
index 82682eae88c705031057ad0fa351a4d66a73295b..fc1d9bf91840193fb6ded4b17dc6acfcaaf00262 100644 (file)
@@ -83,6 +83,29 @@ temporary EWW buffer for our tests."
                        (`(base ((href . ,url)) ,_) url))
                      "http://example.invalid/")))))
 
+(ert-deftest eww-test/tag/textarea/starts-on-new-line ()
+  "Test that inserting a newline before a <textarea> works correctly."
+  (skip-unless (libxml-available-p))
+  (eww-test--with-mock-retrieve
+    (let ((shr-fill-text nil)
+          (eww-test--response-function
+           (lambda (_url)
+             (concat "Content-Type: text/html\n\n"
+                     "<html><body>"
+                     "field: <textarea>text</textarea>"
+                     "</body></html>"))))
+      (eww "example.invalid")
+      ;; Make sure the text before the <textarea> doesn't have any of
+      ;; the <textarea> properties.
+      (goto-char (point-min))
+      (should-not (get-text-property (point) 'eww-form))
+      (should (eq (get-text-property (point) 'face) 'shr-text))
+      ;; Make sure the <textarea> has the correct properties.
+      (forward-line 1)
+      (should (get-text-property (point) 'eww-form))
+      (should (eq (get-text-property (point) 'face)
+                  'eww-form-textarea)))))
+
 (ert-deftest eww-test/history/new-page ()
   "Test that when visiting a new page, the previous one goes into the history."
   (eww-test--with-mock-retrieve