bug#28907: 26.0.90; [eww] some problems in input/textarea

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

bug#28907: 26.0.90; [eww] some problems in input/textarea

Katsumi Yamaoka
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.


--- 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
Reply | Threaded
Open this post in threaded view
|

bug#28907: 26.0.90; [eww] some problems in input/textarea

Eli Zaretskii
> Date: Fri, 20 Oct 2017 17:39:29 +0900
> From: Katsumi Yamaoka <[hidden email]>
>
> 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.

Lars, any comments?  Should we install this, and if so, on what
branch?



Reply | Threaded
Open this post in threaded view
|

bug#28907: 26.0.90; [eww] some problems in input/textarea

Katsumi Yamaoka
In reply to this post by Katsumi Yamaoka
On Fri, 27 Oct 2017 16:31:49 +0300, Eli Zaretskii wrote:
>> Date: Fri, 20 Oct 2017 17:39:29 +0900
>> From: Katsumi Yamaoka <[hidden email]>

>> 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.

> Lars, any comments?  Should we install this, and if so, on what
> branch?

Please don't install my patch as is, as I realized it is not
necessarily a better solution.  In particular, to make kill and
yank work properly, we would have to improve the handling of
inlined editable input/textarea further.  Though I'm not sure
whether I can reach to the best result, I'd like to work on it.

Thanks.



Reply | Threaded
Open this post in threaded view
|

bug#28907: 26.0.90; [eww] some problems in input/textarea

Katsumi Yamaoka
In reply to this post by Katsumi Yamaoka
On Mon, 30 Oct 2017 08:30:39 +0900, Katsumi Yamaoka wrote:
> On Fri, 27 Oct 2017 16:31:49 +0300, Eli Zaretskii wrote:
>>> Date: Fri, 20 Oct 2017 17:39:29 +0900
>>> From: Katsumi Yamaoka <[hidden email]>

>>> 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.

[...]

> Please don't install my patch as is, as I realized it is not
> necessarily a better solution.  In particular, to make kill and
> yank work properly, we would have to improve the handling of
> inlined editable input/textarea further.  Though I'm not sure
> whether I can reach to the best result, I'd like to work on it.

Progress report:
・Implementing `kill' and `yank' features have been almost done.
・`yank-pop' is in progress.
・No idea for making `undo' work properly so far.

http://www.jpl.org/tmp/eww-20171102.el

Regards,
(I will be absent till Monday.)



Reply | Threaded
Open this post in threaded view
|

bug#28907: 26.0.90; [eww] some problems in input/textarea

Katsumi Yamaoka
In reply to this post by Katsumi Yamaoka
On Thu, 02 Nov 2017 16:39:53 +0900, Katsumi Yamaoka wrote:
> On Mon, 30 Oct 2017 08:30:39 +0900, Katsumi Yamaoka wrote:
>> On Fri, 27 Oct 2017 16:31:49 +0300, Eli Zaretskii wrote:
>>>> Date: Fri, 20 Oct 2017 17:39:29 +0900
>>>> From: Katsumi Yamaoka <[hidden email]>

>>>> 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.

[...]

Some generic editing commands, except for `undo', now almost work
in input/textarea.  To try writing something in those fields, you
can use the following two pages:

<https://html.com/tags/input/#Code_Example>
<https://html.com/tags/textarea/#Code_Example>

A patch is below.

* lisp/net/eww.el (eww-preprocess-text-input): New function that
calculates changed length based on string width, not characters.
(eww-render): Add it to before-change-functions.
(eww-tag-a): Make keymap text property non-sticky.
(eww-text-map, eww-textarea-map): Remap some generic editing keys.
(eww-beginning-of-text, eww-end-of-text): Work on textarea as well.
(eww-field-extract-text, eww-field-uniline-text, eww-field-insert-text)
(eww-field-funcall): New functions.
(eww-field-backward-delete-char-untabify)
(eww-field-delete-backward-char, eww-field-delete-char)
(eww-field-kill-line, eww-field-kill-region, eww-field-newline)
(eww-field-open-line, eww-field-yank, eww-field-yank-pop): New commands.
(eww-form-text): Pass field width to eww-form property.
(eww-field-replace-length): New internal variable.
(eww-process-text-input): Use string width based changed length;
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;
pass field width and height to eww-form property.
(eww-size-text-inputs): Make the field end position a marker.


attachment0 (19K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

bug#28907: 26.0.90; [eww] some problems in input/textarea

Eli Zaretskii
> Date: Fri, 10 Nov 2017 16:57:23 +0900
> From: Katsumi Yamaoka <[hidden email]>
> Cc: Lars Ingebrigtsen <[hidden email]>, [hidden email]
>
> Some generic editing commands, except for `undo', now almost work
> in input/textarea.  To try writing something in those fields, you
> can use the following two pages:
>
> <https://html.com/tags/input/#Code_Example>
> <https://html.com/tags/textarea/#Code_Example>
>
> A patch is below.

You say "almost work" because you are still working on this?  Or is
this patch complete enough to push it?

Anyway, looks like quite a large changeset, almost a new feature.
Should we put it on master or do you think it should be on the release
branch for some reason?

Lars, any comments?

Thanks.



Reply | Threaded
Open this post in threaded view
|

bug#28907: 26.0.90; [eww] some problems in input/textarea

Katsumi Yamaoka
In reply to this post by Katsumi Yamaoka
On Fri, 10 Nov 2017 10:28:52 +0200, Eli Zaretskii wrote:
> You say "almost work" because you are still working on this?  Or is
> this patch complete enough to push it?

It's complete at this time.  Even though there might be some
minor bugs (and they will be likely, maybe), it should be better
than the existing one.

> Anyway, looks like quite a large changeset, almost a new feature.
> Should we put it on master or do you think it should be on the release
> branch for some reason?

I don't want to install it to the release branch so much, as it
is big as you say, and it might break the simpleness of eww.el.
So,

> Lars, any comments?

Regards,



Reply | Threaded
Open this post in threaded view
|

bug#28907: 26.0.90; [eww] some problems in input/textarea

Katsumi Yamaoka
In reply to this post by Katsumi Yamaoka
On Fri, 10 Nov 2017 16:57:23 +0900, Katsumi Yamaoka wrote:
> Some generic editing commands, except for `undo', now almost work
> in input/textarea.  To try writing something in those fields, you
> can use the following two pages:

> <https://html.com/tags/input/#Code_Example>
> <https://html.com/tags/textarea/#Code_Example>

Here is a revised patch:

<http://www.jpl.org/tmp/eww.el-20171114.patch>



Reply | Threaded
Open this post in threaded view
|

bug#28907: 26.0.90; [eww] some problems in input/textarea

Katsumi Yamaoka
In reply to this post by Katsumi Yamaoka
On Tue, 14 Nov 2017 17:26:02 +0900, Katsumi Yamaoka wrote:
> On Fri, 10 Nov 2017 16:57:23 +0900, Katsumi Yamaoka wrote:
>> Some generic editing commands, except for `undo', now almost work
>> in input/textarea.  To try writing something in those fields, you
>> can use the following two pages:

>> <https://html.com/tags/input/#Code_Example>
>> <https://html.com/tags/textarea/#Code_Example>

I've implemented `undo' at last.  It is still somewhat buggy, so
I will improve it further.  It's a good brain exercise anyway. ;-)

<http://www.jpl.org/tmp/eww.el-20171117.patch>