diff --git a/CHANGELOG.org b/CHANGELOG.org index f358127..b31576e 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -5,6 +5,7 @@ * Development - Ensure that the popup font matches the font of the parent frame. +- Close popup when window selection changes. * Version 0.36 (2023-03-27) diff --git a/corfu.el b/corfu.el index 7c0c812..e9f5bc1 100644 --- a/corfu.el +++ b/corfu.el @@ -785,6 +785,8 @@ FRAME is the existing frame." (activate-change-group (setq corfu--change-group (prepare-change-group))) (setcdr (assq #'completion-in-region-mode minor-mode-overriding-map-alist) corfu-map) (add-hook 'pre-command-hook #'corfu--prepare nil 'local) + (add-hook 'window-selection-change-functions #'corfu-quit nil 'local) + (add-hook 'window-buffer-change-functions #'corfu-quit nil 'local) (add-hook 'post-command-hook #'corfu--post-command) ;; Disable default post-command handling, since we have our own ;; checks in `corfu--post-command'. @@ -1074,6 +1076,8 @@ AUTO is non-nil when initializing auto completion." (cl-defgeneric corfu--teardown () "Tear-down Corfu." (corfu--popup-hide) + (remove-hook 'window-selection-change-functions #'corfu-quit 'local) + (remove-hook 'window-buffer-change-functions #'corfu-quit 'local) (remove-hook 'pre-command-hook #'corfu--prepare 'local) (remove-hook 'post-command-hook #'corfu--post-command) (when corfu--preview-ov (delete-overlay corfu--preview-ov)) @@ -1084,7 +1088,7 @@ AUTO is non-nil when initializing auto completion." "Sort LIST by length and alphabetically." (sort list #'corfu--length-string<)) -(defun corfu-quit () +(defun corfu-quit (&rest _) "Quit Corfu completion." (interactive) (completion-in-region-mode -1))