]> git.eshelyaron.com Git - completion-preview.git/commitdiff
Handle non-zero completion base offset
authorEshel Yaron <me@eshelyaron.com>
Sun, 29 Oct 2023 12:07:46 +0000 (13:07 +0100)
committerEshel Yaron <me@eshelyaron.com>
Sun, 29 Oct 2023 12:07:46 +0000 (13:07 +0100)
completion-preview.el

index 49b8bff7d9e3fbf1d084e2786f59211af075e199..1074e120d8148e61aac37f2d7bdcde2aed4cc1c7 100644 (file)
@@ -119,10 +119,12 @@ Compatibility definition for `minibuffer--sort-by-length-alpha'."
                                                (or (plist-get plist :predicate)
                                                    completion-preview-predicate)
                                                (- (point) beg) md))
-              (last (last all)))
+              (last (last all))
+              (base (or (cdr last) 0))
+              (prefix (substring string base)))
          (when last
            (setcdr last nil)
-           (let* ((filtered (seq-filter (apply-partially #'string-prefix-p string)
+           (let* ((filtered (seq-filter (apply-partially #'string-prefix-p prefix)
                                         all))
                   (sorted (funcall sort-fn filtered))
                   (multi (cadr sorted)) ; multiple candidates
@@ -130,7 +132,7 @@ Compatibility definition for `minibuffer--sort-by-length-alpha'."
              (when (and cand
                         (not (and multi completion-preview-exact-match-only)))
                (let* ((face (if multi 'completion-preview 'completion-preview-exact))
-                      (after (propertize (substring cand (length string)) 'face face)))
+                      (after (propertize (substring cand (length prefix)) 'face face)))
                  (unless (string-empty-p after)
                    (add-text-properties 0 1 '(cursor 1) after))
                  (setq completion-preview--overlay (make-overlay end end))