branch: master
commit 97cf30dc9cb5473a1d6b0ff67950be556eb3de31
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
Add multiple-cursors support to ivy-completion-in-region-action
* ivy.el (ivy-completion-in-region-action): Do the same thing for each
cursor as for point, with respective offset.
Fixes #547
---
ivy.el | 35 ++++++++++++++++++++++++++---------
1 file changed, 26 insertions(+), 9 deletions(-)
diff --git a/ivy.el b/ivy.el
index b661a6d..f4f590d 100644
--- a/ivy.el
+++ b/ivy.el
@@ -1635,20 +1635,37 @@ INHERIT-INPUT-METHOD is currently ignored."
(defvar ivy-completion-end nil
"Completion bounds end.")
+(declare-function mc/all-fake-cursors "ext:multiple-cursors-core")
+
(defun ivy-completion-in-region-action (str)
"Insert STR, erasing the previous one.
The previous string is between `ivy-completion-beg' and `ivy-completion-end'."
(when (stringp str)
(with-ivy-window
- (when ivy-completion-beg
- (delete-region
- ivy-completion-beg
- ivy-completion-end))
- (setq ivy-completion-beg
- (move-marker (make-marker) (point)))
- (insert (substring-no-properties str))
- (setq ivy-completion-end
- (move-marker (make-marker) (point))))))
+ (let ((fake-cursors (and (featurep 'multiple-cursors)
+ (mc/all-fake-cursors)))
+ (pt (point))
+ (beg ivy-completion-beg)
+ (end ivy-completion-end))
+ (when ivy-completion-beg
+ (delete-region
+ ivy-completion-beg
+ ivy-completion-end))
+ (setq ivy-completion-beg
+ (move-marker (make-marker) (point)))
+ (insert (substring-no-properties str))
+ (setq ivy-completion-end
+ (move-marker (make-marker) (point)))
+ (save-excursion
+ (dolist (cursor fake-cursors)
+ (goto-char (overlay-start cursor))
+ (delete-region (+ (point) (- beg pt))
+ (+ (point) (- end pt)))
+ (insert (substring-no-properties str))
+ ;; manually move the fake cursor
+ (move-overlay cursor (point) (1+ (point)))
+ (move-marker (overlay-get cursor 'point) (point))
+ (move-marker (overlay-get cursor 'mark) (point))))))))
(defun ivy-completion-common-length (str)
"Return the length of the first 'completions-common-part face in STR."