branch: master
commit 55e34e887946690a5c8f05403f5fc352c31c3b8d
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
ivy.el (ivy-completion-in-region): Use :initial-input and :unwind
Previously, Ivy's "prefixing" and "perfect match" index logic was
messed up for completion-in-region. The reason being is that the
initial prefix was never passed to Ivy: instead, the collection was
pre-filtered on the prefix and a "new" completion session didn't know
about it.
With this change:
- the initial prefix is passed to `ivy-read' as :initial-input,
- since the initial prefix is expected to remain on "C-g", a special
:unwind lambda was added,
- the collection is still pre-filtered on the initial prefix, even if
you erase the initial input, the full candidates won't be restored.
---
ivy.el | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/ivy.el b/ivy.el
index f630dc3..c793317 100644
--- a/ivy.el
+++ b/ivy.el
@@ -2010,8 +2010,9 @@ See `completion-in-region' for further information."
(let ((len (min (ivy-completion-common-length (car comps))
(length str))))
(nconc comps nil)
- (setq ivy-completion-beg (- end len))
- (setq ivy-completion-end end)
+ (delete-region start end)
+ (setq ivy-completion-beg start)
+ (setq ivy-completion-end start)
(if (null (cdr comps))
(if (string= str (car comps))
(message "Sole match")
@@ -2032,7 +2033,12 @@ See `completion-in-region' for further information."
;; remove 'completions-first-difference face
(mapcar #'substring-no-properties comps)
:predicate predicate
+ :initial-input str
:action #'ivy-completion-in-region-action
+ :unwind (lambda ()
+ (unless (eq ivy-exit 'done)
+ (goto-char start)
+ (insert str)))
:caller 'ivy-completion-in-region)
t)))))))