branch: externals/minuet
commit 8ac7e004c598067dad86181c34ca9a20d64ddf49
Author: Milan Glacier <[email protected]>
Commit: Milan Glacier <[email protected]>

    fix: ensure correct overlay cursor positioning on empty lines.
    
    When a completion suggestion contains an empty line, the Emacs overlay
    can sometimes be positioned before the cursor rather than after it.
    
    This change replaces empty lines in the suggestion string with a single
    space before applying it to the overlay. This ensures the overlay text
    remains correctly positioned after the cursor, maintaining consistent
    visual behavior during completion.
---
 minuet.el | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/minuet.el b/minuet.el
index 9427614593..b447243c37 100644
--- a/minuet.el
+++ b/minuet.el
@@ -539,6 +539,12 @@ Return non-nil when the completion was preserved or 
updated."
               (total (length suggestions))
               (index (mod (or index 0) total))
               (suggestion (nth index suggestions))
+              ;; Prepare the display text for the overlay by replacing
+              ;; empty lines with a space. This ensures that if the
+              ;; current line is an empty line, the overlay text is
+              ;; correctly positioned after the cursor, rather than
+              ;; before it.
+              (overlay-text (replace-regexp-in-string "^$" " " suggestion))
               ;; 'Display' is used when not at the end-of-line to
               ;; ensure proper overlay positioning. Other methods,
               ;; such as `after-string' or `before-string', fail to
@@ -560,12 +566,12 @@ Return non-nil when the completion was preserved or 
updated."
     ;; HACK: Adapted from copilot.el We add a 'cursor text property to the
     ;; first character of the suggestion to simulate the visual effect of
     ;; placing the overlay after the cursor
-    (put-text-property 0 1 'cursor t suggestion)
+    (put-text-property 0 1 'cursor t overlay-text)
     (overlay-put ov ov-method
                  (concat
                   (propertize
                    (format "%s%s"
-                           suggestion
+                           overlay-text
                            (if (= total minuet-n-completions 1) ""
                              (format " (%d/%d)" (1+ index) total)))
                    'face 'minuet-suggestion-face)

Reply via email to