(should (eq t (company--good-prefix-p "abc")))
(should (eq t (company--good-prefix-p '("bar" . t)))))))
+(ert-deftest company-common-with-non-prefix-completion ()
+ (let ((company-backend #'ignore)
+ (company-prefix "abc")
+ company-candidates
+ company-candidates-length
+ company-candidates-cache
+ company-common)
+ (company-update-candidates '("abc" "def-abc"))
+ (should (null company-common))
+ (company-update-candidates '("abc" "abe-c"))
+ (should (null company-common))
+ (company-update-candidates '("abcd" "abcde" "abcdf"))
+ (should (equal "abcd" company-common))))
+
(ert-deftest company-multi-backend-with-lambdas ()
(let ((company-backend
(list (lambda (command &optional arg &rest ignore)
;; We want to support non-prefix completion, so filtering is the
;; responsibility of each respective backend, not ours.
;; On the other hand, we don't want to replace non-prefix input in
- ;; `company-complete-common'.
+ ;; `company-complete-common', unless it's the sole candidate.
(setq company-common
(if (cdr company-candidates)
- (let ((common (try-completion company-prefix company-candidates)))
- (if (eq common t)
- ;; Mulple equal strings, probably with different
- ;; annotations.
- company-prefix
+ (let ((common (try-completion "" company-candidates)))
+ (when (string-prefix-p company-prefix common)
common))
(car company-candidates)))))