summaryrefslogtreecommitdiff
path: root/lisp/xwidget.el
diff options
context:
space:
mode:
authorPo Lu <luangruo@yahoo.com>2021-11-12 17:48:56 +0800
committerPo Lu <luangruo@yahoo.com>2021-11-12 17:50:20 +0800
commit2803cabe890b3ec47f54ebaa63c84de588809a6f (patch)
treef6b05b5c1c7755b055caccbf1b8ed5dea6bb5839 /lisp/xwidget.el
parent00e3baf6e32d39c8434f50e1f0b0a83ad2ad3aeb (diff)
downloademacs-2803cabe890b3ec47f54ebaa63c84de588809a6f.tar.gz
Add support for input methods to xwidget-webkit-edit-mode
* lisp/xwidget.el (xwidget-webkit--input-method-events): New variable. (xwidget-webkit-pass-command-event-with-input-method): New function. (xwidget-webkit-pass-command-event): Consult input method about key events if input method is enabled.
Diffstat (limited to 'lisp/xwidget.el')
-rw-r--r--lisp/xwidget.el31
1 files changed, 28 insertions, 3 deletions
diff --git a/lisp/xwidget.el b/lisp/xwidget.el
index 3d4e96f92d0..e98143b9559 100644
--- a/lisp/xwidget.el
+++ b/lisp/xwidget.el
@@ -146,11 +146,36 @@ in `split-window-right' with a new xwidget webkit session."
(declare-function xwidget-perform-lispy-event "xwidget.c")
+(defvar xwidget-webkit--input-method-events nil
+ "Internal variable used to store input method events.")
+
+(defun xwidget-webkit-pass-command-event-with-input-method ()
+ "Handle a `with-input-method' event."
+ (interactive)
+ (let ((key (pop unread-command-events)))
+ (setq xwidget-webkit--input-method-events
+ (funcall input-method-function key))
+ (exit-minibuffer)))
+
(defun xwidget-webkit-pass-command-event ()
- "Pass `last-command-event' to the current buffer's WebKit widget."
+ "Pass `last-command-event' to the current buffer's WebKit widget.
+If `current-input-method' is non-nil, consult `input-method-function'
+for the actual events that will be sent."
(interactive)
- (xwidget-perform-lispy-event (xwidget-webkit-current-session)
- last-command-event))
+ (if (and current-input-method
+ (characterp last-command-event))
+ (let ((xwidget-webkit--input-method-events nil)
+ (minibuffer-local-map (make-keymap)))
+ (define-key minibuffer-local-map [with-input-method]
+ 'xwidget-webkit-pass-command-event-with-input-method)
+ (push last-command-event unread-command-events)
+ (push 'with-input-method unread-command-events)
+ (read-from-minibuffer "" nil nil nil nil nil t)
+ (dolist (event xwidget-webkit--input-method-events)
+ (xwidget-perform-lispy-event (xwidget-webkit-current-session)
+ event)))
+ (xwidget-perform-lispy-event (xwidget-webkit-current-session)
+ last-command-event)))
;;todo.
;; - check that the webkit support is compiled in