summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mendler <mail@daniel-mendler.de>2021-11-18 22:36:05 +0100
committerDaniel Mendler <mail@daniel-mendler.de>2021-11-18 22:36:29 +0100
commit2f0dcbb5978d757d99bb343ed5440ffeba69cee1 (patch)
tree56f8a0e90f42873bc380460fd5442fa0f9a9d42b
parent24f314dad51d4aea42eb6f672f19ced400a122f1 (diff)
Improve corfu-reset
This command can be executed multiple times consecutively by hammering the ESC key. If a candidate is selected, unselect the candidate. Otherwise reset the input. If there hasn't been any input, then quit.
-rw-r--r--corfu.el18
1 files changed, 11 insertions, 7 deletions
diff --git a/corfu.el b/corfu.el
index 8008712..9f42145 100644
--- a/corfu.el
+++ b/corfu.el
@@ -599,14 +599,18 @@ A scroll bar is displayed from LO to LO+BAR."
(completion-in-region-mode -1))
(defun corfu-reset ()
- "Reset Corfu completion and quit if reset has been executed twice."
+ "Reset Corfu completion.
+This command can be executed multiple times consecutively by hammering the ESC
+key. If a candidate is selected, unselect the candidate. Otherwise reset the
+input. If there hasn't been any input, then quit."
(interactive)
- (setq corfu--index -1)
- ;; Cancel all changes and start new change group.
- (cancel-change-group corfu--change-group)
- (activate-change-group (setq corfu--change-group (prepare-change-group)))
- (when (eq last-command #'corfu-reset)
- (corfu-quit)))
+ (if (>= corfu--index 0)
+ (corfu--goto -1)
+ (let ((quit (eq buffer-undo-list (cdar corfu--change-group)))) ;; Change group is empty
+ ;; Cancel all changes and start new change group.
+ (cancel-change-group corfu--change-group)
+ (activate-change-group (setq corfu--change-group (prepare-change-group)))
+ (when quit (corfu-quit)))))
(defun corfu--affixate (cands)
"Annotate CANDS with annotation function."