]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix next-line-completion for multi-line completions
authorSpencer Baugh <sbaugh@janestreet.com>
Wed, 24 Jan 2024 15:52:40 +0000 (10:52 -0500)
committerEshel Yaron <me@eshelyaron.com>
Thu, 25 Jan 2024 18:06:02 +0000 (19:06 +0100)
Previously it would not move out of a multi-line completion, and now it will.

* lisp/simple.el (next-line-completion): Move to the completion start
or end before going forward or backward lines.  (bug#68688)

(cherry picked from commit 28c9c7cf464c87e90567f8b0e04f854163aa6187)

lisp/simple.el
test/lisp/minibuffer-tests.el

index 42f2ae24696dcc3bfd55a432ea3fa21d1e949890..32431082f8e5a2dc9f700b05443e7cd415ce978c 100644 (file)
@@ -10035,6 +10035,20 @@ Also see the `completion-auto-wrap' variable."
   (interactive "p")
   (next-completion (- n)))
 
+(defun completion--move-to-candidate-start ()
+  "If in a completion candidate, move point to its start."
+  (when (and (get-text-property (point) 'mouse-face)
+             (not (bobp))
+             (get-text-property (1- (point)) 'mouse-face))
+    (goto-char (previous-single-property-change (point) 'mouse-face))))
+
+(defun completion--move-to-candidate-end ()
+  "If in a completion candidate, move point to its end."
+  (when (and (get-text-property (point) 'mouse-face)
+             (not (eobp))
+             (get-text-property (1+ (point)) 'mouse-face))
+    (goto-char (or (next-single-property-change (point) 'mouse-face) (point-max)))))
+
 (defun next-completion (n)
   "Move to the next item in the completions buffer.
 With prefix argument N, move N items (negative N means move
@@ -10124,9 +10138,7 @@ Also see the `completion-auto-wrap' variable."
 
     (if (get-text-property (point) 'mouse-face)
         ;; If in a completion, move to the start of it.
-        (when (and (not (bobp))
-                   (get-text-property (1- (point)) 'mouse-face))
-          (goto-char (previous-single-property-change (point) 'mouse-face)))
+        (completion--move-to-candidate-start)
       ;; Try to move to the previous completion.
       (setq pos (previous-single-property-change (point) 'mouse-face))
       (if pos
@@ -10141,6 +10153,7 @@ Also see the `completion-auto-wrap' variable."
 
     (while (> n 0)
       (setq found nil pos nil column (current-column) line (line-number-at-pos))
+      (completion--move-to-candidate-end)
       (while (and (not found)
                   (eq (forward-line 1) 0)
                   (not (eobp))
@@ -10165,6 +10178,7 @@ Also see the `completion-auto-wrap' variable."
 
     (while (< n 0)
       (setq found nil pos nil column (current-column) line (line-number-at-pos))
+      (completion--move-to-candidate-start)
       (while (and (not found)
                   (eq (forward-line -1) 0)
                   (eq (move-to-column column) column))
index f3280dbf40122f49380e09286e6cd59c53461984..57a7f345da410bd67a448ccd83ce9e306620a3c9 100644 (file)
       (previous-line-completion 4)
       (should (equal "ac" (get-text-property (point) 'completion--string))))))
 
+(ert-deftest completion-next-line-multline-test ()
+  (let ((completion-auto-wrap t))
+    (completing-read-with-minibuffer-setup
+     '("a\na" "a\nb" "ac")
+     (insert "a")
+     (minibuffer-completion-help)
+     (switch-to-completions)
+     (goto-char (point-min))
+     (next-line-completion 5)
+     (should (equal "a\nb" (get-text-property (point) 'completion--string)))
+     (goto-char (point-min))
+     (previous-line-completion 5)
+     (should (equal "a\nb" (get-text-property (point) 'completion--string))))))
+
 (ert-deftest completions-header-format-test ()
   (let ((completion-show-help nil)
         (completions-header-format nil))