[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/vertico 298379e 4/4: Ensure that vertico-mouse+buffer w
From: |
ELPA Syncer |
Subject: |
[elpa] externals/vertico 298379e 4/4: Ensure that vertico-mouse+buffer works |
Date: |
Sat, 30 Oct 2021 11:57:31 -0400 (EDT) |
branch: externals/vertico
commit 298379e0b3792a72b61ea25d27c8a6b384e9a884
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>
Ensure that vertico-mouse+buffer works
---
extensions/vertico-mouse.el | 33 +++++++++++++++------------------
1 file changed, 15 insertions(+), 18 deletions(-)
diff --git a/extensions/vertico-mouse.el b/extensions/vertico-mouse.el
index 9d66aa1..b83ce57 100644
--- a/extensions/vertico-mouse.el
+++ b/extensions/vertico-mouse.el
@@ -37,19 +37,20 @@
"Face used for mouse highlighting."
:group 'vertico-faces)
-(defun vertico-mouse-exit (event)
- "Exit after mouse EVENT."
- (interactive "@e")
- (when-let* ((obj (posn-string (event-start event)))
- (vertico--index (get-text-property (cdr obj)
'vertico--mouse-index (car obj))))
- (vertico-exit)))
-
-(defun vertico-mouse-insert (event)
- "Insert after mouse EVENT."
- (interactive "@e")
- (when-let* ((obj (posn-string (event-start event)))
- (vertico--index (get-text-property (cdr obj)
'vertico--mouse-index (car obj))))
- (vertico-insert)))
+(defun vertico--mouse-candidate-map (index)
+ "Return keymap for candidate with INDEX."
+ (let ((map (make-sparse-keymap)))
+ (define-key map [mouse-1] (lambda ()
+ (interactive)
+ (with-selected-window
(active-minibuffer-window)
+ (let ((vertico--index index))
+ (vertico-exit)))))
+ (define-key map [mouse-3] (lambda ()
+ (interactive)
+ (with-selected-window
(active-minibuffer-window)
+ (let ((vertico--index index))
+ (vertico-insert)))))
+ map))
(defun vertico-mouse--format-candidate (orig cand prefix suffix index start)
"Format candidate, see `vertico--format-candidate' for arguments."
@@ -61,7 +62,7 @@
(when (= index vertico--index)
(add-face-text-property 0 (length cand) 'vertico-current 'append cand)))
(add-text-properties 0 (1- (length cand))
- `(mouse-face vertico-mouse vertico--mouse-index ,index)
+ `(mouse-face vertico-mouse keymap
,(vertico--mouse-candidate-map index))
cand)
cand)
@@ -84,13 +85,9 @@
:global t :group 'vertico
(cond
(vertico-mouse-mode
- (define-key vertico-map [mouse-1] #'vertico-mouse-exit)
- (define-key vertico-map [mouse-3] #'vertico-mouse-insert)
(advice-add #'vertico--format-candidate :around
#'vertico-mouse--format-candidate)
(advice-add #'vertico--setup :after #'vertico-mouse--setup))
(t
- (assq-delete-all 'mouse-1 vertico-map)
- (assq-delete-all 'mouse-3 vertico-map)
(advice-remove #'vertico--format-candidate
#'vertico-mouse--format-candidate)
(advice-remove #'vertico--setup #'vertico-reverse--setup))))