* Fixes #24 follow-up.
* Cleaner code, less display magic.
(ert-deftest company-modify-line-with-line-prefix ()
(let ((str (propertize "foobar" 'line-prefix "-*-")))
(ert-deftest company-modify-line-with-line-prefix ()
(let ((str (propertize "foobar" 'line-prefix "-*-")))
- (should (string= (company-modify-line str "zz" 4)
- "fzzbar"))
- (should (string= (company-modify-line str "zzxx" 0)
- "zzxxoobar"))
- (should (string= (company-modify-line str "zzxx" 0)
- "zzxxoobar"))
- (should (string= (company-modify-line str "zz" 10)
- "foobar zz"))))
+ (should (equal-including-properties
+ (company-modify-line str "zz" 4)
+ "-*-fzzbar"))
+ (should (equal-including-properties
+ (company-modify-line str "zzxx" 1)
+ "-zzxxobar"))
+ (should (equal-including-properties
+ (company-modify-line str "xx" 0)
+ "xx-foobar"))
+ (should (equal-including-properties
+ (company-modify-line str "zz" 10)
+ "-*-foobar zz"))))
(nreverse lines)))
(defun company-modify-line (old new offset)
(nreverse lines)))
(defun company-modify-line (old new offset)
- (let ((prefix (get-text-property 0 'line-prefix old))
- before)
- (when prefix
- (if (<= offset (length prefix))
- (setq before (substring prefix 0 offset)))
- (decf offset (length prefix)))
- (concat (or before (company-safe-substring old 0 offset))
+ (let ((prefix (get-text-property 0 'line-prefix old)))
+ (when prefix ; Keep the original value unmodified, for no special reason.
+ (setq old (concat prefix old))
+ (remove-text-properties 0 (length old) '(line-prefix) old))
+ (concat (company-safe-substring old 0 offset)
- (company-safe-substring old
- (max (+ offset (length new)) 0)))))
+ (company-safe-substring old (+ offset (length new))))))
(defsubst company--length-limit (lst limit)
(if (nthcdr limit lst)
(defsubst company--length-limit (lst limit)
(if (nthcdr limit lst)
(overlay-put company-pseudo-tooltip-overlay 'invisible t)
;; Beat outline's folding overlays, at least.
(overlay-put company-pseudo-tooltip-overlay 'priority 1)
(overlay-put company-pseudo-tooltip-overlay 'invisible t)
;; Beat outline's folding overlays, at least.
(overlay-put company-pseudo-tooltip-overlay 'priority 1)
+ ;; No (extra) prefix for the first line.
+ (overlay-put company-pseudo-tooltip-overlay 'line-prefix "")
(overlay-put company-pseudo-tooltip-overlay 'before-string
(overlay-get company-pseudo-tooltip-overlay 'company-before))
(overlay-put company-pseudo-tooltip-overlay 'window (selected-window))))
(overlay-put company-pseudo-tooltip-overlay 'before-string
(overlay-get company-pseudo-tooltip-overlay 'company-before))
(overlay-put company-pseudo-tooltip-overlay 'window (selected-window))))