Open jwiegley opened 6 years ago
I have the same problem with the similar setup.
I actually tried once again and narrowed misbehaviour.
tldr; If you have matched string upwards (not showed in the window) then additional cursor appears.
Steps to reproduce:
F3
hello <CR>
F4
C-u 100 F4
(it is important that number of generated lines > number of visible lines)Happy path (all ok)
Bug path
Result: additional cursor is created:
So there is a function swiper--action
which is called for each candidate on swiper-mc.
If you comment out
(swiper--current-window-start
(set-window-start (selected-window) swiper--current-window-start))
then it no additional cursor is created but cursor is on first matched string.
(defun swiper--action (x)
"Goto line X."
(let ((ln (1- (read (or (get-text-property 0 'swiper-line-number x)
(and (string-match ":\\([0-9]+\\):.*\\'" x)
(match-string-no-properties 1 x))))))
(re (ivy--regex ivy-text)))
(if (null x)
(user-error "No candidates")
(with-ivy-window
(unless (equal (current-buffer)
(ivy-state-buffer ivy-last))
(switch-to-buffer (ivy-state-buffer ivy-last)))
(goto-char swiper--point-min)
(funcall (if swiper-use-visual-line
#'line-move
#'forward-line)
ln)
(when (and (re-search-forward re (line-end-position) t) swiper-goto-start-of-match)
(goto-char (match-beginning 0)))
(swiper--ensure-visible)
(cond (swiper-action-recenter
(recenter))
;; HERE ;; (swiper--current-window-start
;; HERE ;; (set-window-start (selected-window) swiper--current-window-start))
)
(when (/= (point) swiper--opoint)
(unless (and transient-mark-mode mark-active)
(when (eq ivy-exit 'done)
(push-mark swiper--opoint t)
(message "Mark saved where search started"))))
(add-to-history
'regexp-search-ring
re
regexp-search-ring-max)
;; integration with evil-mode's search
(when (bound-and-true-p evil-mode)
(when (eq evil-search-module 'isearch)
(setq isearch-string ivy-text))
(when (eq evil-search-module 'evil-search)
(add-to-history 'evil-ex-search-history re)
(setq evil-ex-search-pattern (list re t t))
(setq evil-ex-search-direction 'forward)
(when evil-ex-search-persistent-highlight
(evil-ex-search-activate-highlight evil-ex-search-pattern))))))))
And the temporary fix for the problem is to define a new function and bind it instead of swiper-mc
for ex:
(use-package swiper
:bind (:map swiper-map
("M-c" . haba/swiper-mc-fixed))
:init
(bind-key "C-." #'swiper-from-isearch isearch-mode-map)
:config
(defun haba/swiper-mc-fixed()
(interactive)
(setq swiper--current-window-start nil)
(swiper-mc)))
Anyway for multiple cursors it is not that important to stay close to the point where swiper starts searching. With the func above active cursor is on first swiper match.
When I use swiper to search for a word like "use-package" in my init.el, and then hit M-c, I properly get a cursor for every search hit, but I also get another cursor, not colored black like the multiple-cursors, and located somewhere near (but not exactly where) I started the search. It's not on a search hit. But all the operations I know do with multiple-cursors also happen at this stray cursor.
My relevant configuration is: