branch: master
commit 50ead7e09be86e2731635c81efb48962a2305c7e
Author: Oleh Krehel <[email protected]>
Commit: Oleh Krehel <[email protected]>
ivy-test.el (swiper-thing-at-point): Add and fix test
Fixes #2157
---
ivy-test.el | 16 ++++++++++++++++
swiper.el | 10 +++++++++-
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/ivy-test.el b/ivy-test.el
index f8c9727..1d5d9d6 100644
--- a/ivy-test.el
+++ b/ivy-test.el
@@ -1076,6 +1076,22 @@ a buffer visiting a file."
(and (buffer-name temp-buffer)
(kill-buffer temp-buffer)))))))
+(ert-deftest swiper-thing-at-point ()
+ (should
+ (string=
+ (ivy-with-text
+ "let\n|let\nlet"
+ (global-set-key (kbd "C-s") #'swiper-thing-at-point)
+ ("C-s" "RET"))
+ "let\nlet|\nlet"))
+ (should
+ (string=
+ (ivy-with-text
+ "foo\nlet\nbar\n|let\nlet"
+ (global-set-key (kbd "C-s") #'swiper-thing-at-point)
+ ("C-s" "RET"))
+ "foo\nlet\nbar\nlet|\nlet")))
+
(ert-deftest swiper-isearch ()
(should
(string=
diff --git a/swiper.el b/swiper.el
index b103abc..5071cec 100644
--- a/swiper.el
+++ b/swiper.el
@@ -772,7 +772,15 @@ When non-nil, INITIAL-INPUT is the initial search pattern."
candidates
:initial-input initial-input
:keymap swiper-map
- :preselect preselect
+ :preselect
+ (if initial-input
+ (cl-position-if
+ (lambda (x)
+ (= (1+ preselect) (read (get-text-property 0
'swiper-line-number x))))
+ (progn
+ (setq ivy--old-re nil)
+ (ivy--filter initial-input candidates)))
+ preselect)
:require-match t
:update-fn #'swiper--update-input-ivy
:unwind #'swiper--cleanup