Subject: Re: bug#78074: isearch not respecting point when changing direction after scrolling

From: Juri Linkov <[email-masked]>
Date: Tue, 29 Apr 2025 09:46:07 +0300

>> I think this is a bug because it doesn't happen when
>> `isearch-repeat-on-direction-change' has its default value of nil.
>
> Thanks for the bug report.  Maybe we don't need these lines
> in 'isearch-repeat' after all:
>
>     (if (and isearch-other-end isearch-repeat-on-direction-change)
>         (goto-char isearch-other-end))
>
> Could you please try to remove these 2 lines and see whether this
> improves the behavior of changing the direction.

Actually, this still should be used when changing the direction
with point on the current match.  So here is the correct patch:

diff --git a/lisp/isearch.el b/lisp/isearch.el
index 52c5042133e..57df42e1128 100644
--- a/lisp/isearch.el
+++ b/lisp/isearch.el
@@ -1952,7 +1952,9 @@ isearch-repeat
 	      (funcall isearch-wrap-function)
 	    (goto-char (if isearch-forward (point-min) (point-max))))))
     ;; C-s in reverse or C-r in forward, change direction.
-    (if (and isearch-other-end isearch-repeat-on-direction-change)
+    (if (and isearch-other-end isearch-repeat-on-direction-change
+             (or (null isearch-cmds)
+                 (eq (isearch--state-point (car isearch-cmds)) (point))))
         (goto-char isearch-other-end))
     (setq isearch-forward (not isearch-forward)
 	  isearch-success t))