unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#28907: 26.0.90; [eww] some problems in input/textarea
@ 2017-10-20  8:39 Katsumi Yamaoka
  2017-10-27 13:31 ` Eli Zaretskii
  0 siblings, 1 reply; 14+ messages in thread
From: Katsumi Yamaoka @ 2017-10-20  8:39 UTC (permalink / raw)
  To: 28907

[-- Attachment #1: Type: text/plain, Size: 1648 bytes --]

Hi,

There are some problems with an input form and a textarea as
follows:

・Can't enter text at the beginnig of input/textarea if there is
  a link just above the form.
・Can't enter space at (1- eol).
・Can't kill a line.
・Can't undo.
・Can't retrieve the response for the submit in a certain site.
・Padding width gets incorrect if there is a wide character.
・A major mode command like `g' doesn't work at the right outside
  of textarea.

I tested and tried to improve them in mainly:
<https://www.excite.co.jp/world/english/>    [1]
A patch is below.  Some of them would have to be improved further,
though.

Thanks.

[1] This is an English-Japanese translation service; you can
find the textarea slot for entering an original English text at
the line 191 in an eww buffer.  Please note that the translation
is not so accurate. ;-)

P.S. I will be absent from the net till Thursday, sorry.

In GNU Emacs 26.0.90 (build 1, i686-pc-cygwin, GTK+ Version 3.18.9)
 of 2017-10-20 built on localhost
Windowing system distributor 'The Cygwin/X Project', version 11.0.11900000

* lisp/net/eww.el (eww, eww-reload): Disable undo.
(eww-render): Enable undo when a user enters things in input/textarea.
(eww-tag-a): Make keymap prop non-sticky.
(eww-kill-line): New command.
(eww-textarea-map): Use it.
(eww-process-text-input): Enable a user to enter space at (1- eol);
don't break the form when killing a line at the beginning of the form.
(eww-tag-textarea): Treat textarea's text as its value if it is null;
work the padding correctly when there is a wide character;
make keymap prop non-sticky.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Type: text/x-patch, Size: 4439 bytes --]

--- eww.el~	2017-09-14 22:06:50.000000000 +0000
+++ eww.el	2017-10-20 08:36:56.427163000 +0000
@@ -256,6 +256,7 @@
    (if (eq major-mode 'eww-mode)
        (current-buffer)
      (get-buffer-create "*eww*")))
+  (buffer-disable-undo)
   (eww-setup-buffer)
   ;; Check whether the domain only uses "Highly Restricted" Unicode
   ;; IDNA characters.  If not, transform to punycode to indicate that
@@ -397,7 +398,10 @@
 	    (setq eww-history-position 0)
 	    (and last-coding-system-used
 		 (set-buffer-file-coding-system last-coding-system-used))
-	    (run-hooks 'eww-after-render-hook)))
+	    (run-hooks 'eww-after-render-hook)
+	    (add-hook 'before-change-functions
+		      (lambda (&rest _args) (buffer-enable-undo))
+		      nil t)))
       (kill-buffer data-buffer))))
 
 (defun eww-parse-headers ()
@@ -546,7 +550,8 @@
   (eww-handle-link dom)
   (let ((start (point)))
     (shr-tag-a dom)
-    (put-text-property start (point) 'keymap eww-link-keymap)))
+    (add-text-properties start (point) (list 'keymap eww-link-keymap
+					     'rear-nonsticky t))))
 
 (defun eww-update-header-line-format ()
   (setq header-line-format
@@ -916,6 +921,7 @@
 a prefix argument), don't reload the page from the network, but
 just re-display the HTML already fetched."
   (interactive "P")
+  (buffer-disable-undo)
   (let ((url (plist-get eww-data :url)))
     (if local
 	(if (null (plist-get eww-data :dom))
@@ -966,6 +972,7 @@
     (define-key map [(control c) (control c)] 'eww-submit)
     (define-key map [?\t] 'shr-next-link)
     (define-key map [?\M-\t] 'shr-previous-link)
+    (define-key map "\C-k" 'eww-kill-line)
     map))
 
 (defvar eww-select-map
@@ -990,6 +997,13 @@
     (when (> (point) start)
       (forward-char 1))))
 
+;; FIXME: make it usable for `eww-text-map'.
+(defun eww-kill-line (&optional _arg)
+  "Kill the rest of the current line."
+  (interactive "P")
+  (let ((inhibit-read-only t))
+    (kill-region (point) (line-end-position))))
+
 (defun eww-beginning-of-field ()
   (cond
    ((bobp)
@@ -1134,6 +1148,8 @@
 		 (1- (line-end-position))
 	       (eww-end-of-field)))
 	    (while (and (> length 0)
+			;; Don't delete space a user enters at (1- eol).
+			(< end (point))
 			(eql (char-after (1- (point))) ? ))
 	      (delete-region (1- (point)) (point))
 	      (cl-decf length))))
@@ -1141,10 +1157,11 @@
 	  ;; Add padding.
 	  (save-excursion
 	    (goto-char end)
-	    (goto-char
-	     (if (equal type "textarea")
-		 (1- (line-end-position))
-	       (1+ (eww-end-of-field))))
+	    (if (equal type "textarea")
+		;; Don't move point if the line is empty.
+		(unless (and (bolp) (eolp))
+		  (goto-char (1- (line-end-position))))
+	      (goto-char (1+ (eww-end-of-field))))
 	    (let ((start (point)))
               (insert (make-string (abs length) ? ))
 	      (set-text-properties start (point) properties))
@@ -1166,13 +1183,14 @@
                'display (make-string (length value) ?*)))))))))
 
 (defun eww-tag-textarea (dom)
-  (let ((start (point))
-	(value (or (dom-attr dom 'value) ""))
+  (let ((value (or (dom-attr dom 'value) (dom-text dom)))
 	(lines (string-to-number (or (dom-attr dom 'rows) "10")))
 	(width (string-to-number (or (dom-attr dom 'cols) "10")))
-	end)
+	start end)
     (shr-ensure-newline)
-    (insert value)
+    (setq start (point))
+    (let ((fill-column width))
+      (fill-region start (progn (insert value) (point))))
     (shr-ensure-newline)
     (when (< (count-lines start (point)) lines)
       (dotimes (_ (- lines (count-lines start (point))))
@@ -1181,14 +1199,16 @@
     (goto-char start)
     (while (< (point) end)
       (end-of-line)
-      (let ((pad (- width (- (point) (line-beginning-position)))))
+      (let ((pad (- width (current-column)))) ;; There may be a wide character.
 	(when (> pad 0)
 	  (insert (make-string pad ? ))))
       (add-face-text-property (line-beginning-position)
 			      (point) 'eww-form-textarea)
-      (put-text-property (line-beginning-position) (point) 'inhibit-read-only t)
-      (put-text-property (line-beginning-position) (point)
-			 'local-map eww-textarea-map)
+      (add-text-properties (line-beginning-position) (point)
+			   `(inhibit-read-only t
+			     local-map ,eww-textarea-map
+			     ;; Enable the major mode keymap on newlines.
+			     rear-nonsticky t))
       (forward-line 1))
     (put-text-property start (point) 'eww-form
 		       (list :eww-form eww-form

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2018-04-12 22:30 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-20  8:39 bug#28907: 26.0.90; [eww] some problems in input/textarea Katsumi Yamaoka
2017-10-27 13:31 ` Eli Zaretskii
2017-10-29 23:30   ` Katsumi Yamaoka
2017-11-02  7:39     ` Katsumi Yamaoka
2017-11-10  7:57       ` Katsumi Yamaoka
2017-11-10  8:28         ` Eli Zaretskii
2017-11-10  9:10           ` Katsumi Yamaoka
2017-11-14  8:26         ` Katsumi Yamaoka
2017-11-17  8:42           ` Katsumi Yamaoka
2017-12-13  8:19             ` Katsumi Yamaoka
2017-12-15  9:03               ` Eli Zaretskii
2017-12-15  9:58                 ` Katsumi Yamaoka
2017-12-27 21:12             ` Lars Ingebrigtsen
2018-04-12 22:30               ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).