summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPo Lu <luangruo@yahoo.com>2022-01-15 18:18:34 +0800
committerPo Lu <luangruo@yahoo.com>2022-01-15 18:20:15 +0800
commit7a679953e22ada9df02b181b872b9e56bbfd0f07 (patch)
tree58af1eb495e2f3dbdb2a6376644e279dc61adef5
parent3b27edd5f5fe4f9f45f1dd54ec24dcc6181ddca9 (diff)
downloademacs-7a679953e22ada9df02b181b872b9e56bbfd0f07.tar.gz
Prevent pre-edit overlay text from being displayed after a command
This works around buggy input methods causing the overlay to be displayed alongside newly inserted text for a brief period. * lisp/term/x-win.el (x-clear-preedit-text): New function. (x-preedit-text): Add said function to pre-command-hook. It will remove itself when triggered.
-rw-r--r--lisp/term/x-win.el18
1 files changed, 17 insertions, 1 deletions
diff --git a/lisp/term/x-win.el b/lisp/term/x-win.el
index e52e488edab..cd63c9208ba 100644
--- a/lisp/term/x-win.el
+++ b/lisp/term/x-win.el
@@ -1527,16 +1527,32 @@ This uses `icon-map-list' to map icon file names to stock icon names."
(defvar x-preedit-overlay nil
"The overlay currently used to display preedit text from a compose sequence.")
+;; With some input methods, text gets inserted before Emacs is told to
+;; remove any preedit text that was displayed, which causes both the
+;; preedit overlay and the text to be visible for a brief period of
+;; time. This pre-command-hook clears the overlay before any command
+;; and should be set whenever a preedit overlay is visible.
+(defun x-clear-preedit-text ()
+ "Clear the pre-edit overlay and remove itself from pre-command-hook.
+This function should be installed in `pre-command-hook' whenever
+preedit text is displayed."
+ (when x-preedit-overlay
+ (delete-overlay x-preedit-overlay)
+ (setq x-preedit-overlay nil))
+ (remove-hook 'pre-command-hook #'x-clear-preedit-text))
+
(defun x-preedit-text (event)
"Display preedit text from a compose sequence in EVENT.
EVENT is a preedit-text event."
(interactive "e")
(when x-preedit-overlay
(delete-overlay x-preedit-overlay)
- (setq x-preedit-overlay nil))
+ (setq x-preedit-overlay nil)
+ (remove-hook 'pre-command-hook #'x-clear-preedit-text))
(when (nth 1 event)
(let ((string (propertize (nth 1 event) 'face '(:underline t))))
(setq x-preedit-overlay (make-overlay (point) (point)))
+ (add-hook 'pre-command-hook #'x-clear-preedit-text)
(overlay-put x-preedit-overlay 'window (selected-window))
(overlay-put x-preedit-overlay 'before-string
(if x-display-cursor-at-start-of-preedit-string