diff options
| author | Ricardo Wurmus | 2016-10-25 23:00:35 -0700 |
|---|---|---|
| committer | Paul Eggert | 2016-10-25 23:07:13 -0700 |
| commit | ff80a9c8376d5c14e37fbbfde08706492327836a (patch) | |
| tree | 2a63f071e922c2f05f71068bc3b9adf24a800d6d | |
| parent | 7ee870e87c6332c0d2430faf71349f939b59e162 (diff) | |
| download | emacs-ff80a9c8376d5c14e37fbbfde08706492327836a.tar.gz emacs-ff80a9c8376d5c14e37fbbfde08706492327836a.zip | |
xwidget: Do not use `xwidget-execute-script-rv' to insert string
* lisp/xwidget.el (xwidget-webkit-insert-string): Obtain JavaScript
return value via callback instead of using
`xwidget-webkit-execute-script-rv'.
| -rw-r--r-- | lisp/xwidget.el | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/lisp/xwidget.el b/lisp/xwidget.el index d2b9a091254..a252fd75d4b 100644 --- a/lisp/xwidget.el +++ b/lisp/xwidget.el | |||
| @@ -286,31 +286,30 @@ function findactiveelement(doc){ | |||
| 286 | ;;TODO the activeelement type needs to be examined, for iframe, etc. | 286 | ;;TODO the activeelement type needs to be examined, for iframe, etc. |
| 287 | ) | 287 | ) |
| 288 | 288 | ||
| 289 | (defun xwidget-webkit-insert-string (xw str) | 289 | (defun xwidget-webkit-insert-string () |
| 290 | "Insert string STR in the active field in the webkit XW." | 290 | "Prompt for a string and insert it in the active field in the |
| 291 | current webkit widget." | ||
| 291 | ;; Read out the string in the field first and provide for edit. | 292 | ;; Read out the string in the field first and provide for edit. |
| 292 | (interactive | 293 | (interactive) |
| 293 | (let* ((xww (xwidget-webkit-current-session)) | 294 | (let ((xww (xwidget-webkit-current-session))) |
| 294 | 295 | (xwidget-webkit-execute-script | |
| 295 | (field-value | 296 | xww |
| 296 | (progn | 297 | (concat xwidget-webkit-activeelement-js " |
| 297 | (xwidget-webkit-execute-script xww xwidget-webkit-activeelement-js) | 298 | (function () { |
| 298 | (xwidget-webkit-execute-script-rv | 299 | var res = findactiveelement(document); |
| 299 | xww | 300 | return [res.value, res.type]; |
| 300 | "findactiveelement(document).value;"))) | 301 | })();") |
| 301 | (field-type (xwidget-webkit-execute-script-rv | 302 | (lambda (field) |
| 302 | xww | 303 | (let ((str (pcase field |
| 303 | "findactiveelement(document).type;"))) | 304 | (`[,val "text"] |
| 304 | (list xww | 305 | (read-string "Text: " val)) |
| 305 | (cond ((equal "text" field-type) | 306 | (`[,val "password"] |
| 306 | (read-string "Text: " field-value)) | 307 | (read-passwd "Password: " nil val)) |
| 307 | ((equal "password" field-type) | 308 | (`[,val "textarea"] |
| 308 | (read-passwd "Password: " nil field-value)) | 309 | (xwidget-webkit-begin-edit-textarea xww val))))) |
| 309 | ((equal "textarea" field-type) | 310 | (xwidget-webkit-execute-script |
| 310 | (xwidget-webkit-begin-edit-textarea xww field-value)))))) | 311 | xww |
| 311 | (xwidget-webkit-execute-script | 312 | (format "findactiveelement(document).value='%s'" str))))))) |
| 312 | xw | ||
| 313 | (format "findactiveelement(document).value='%s'" str))) | ||
| 314 | 313 | ||
| 315 | (defvar xwidget-xwbl) | 314 | (defvar xwidget-xwbl) |
| 316 | (defun xwidget-webkit-begin-edit-textarea (xw text) | 315 | (defun xwidget-webkit-begin-edit-textarea (xw text) |