]> code.delx.au - gnu-emacs-elpa/commitdiff
Truncate out-of-bounds search highlighting
authorDmitry Gutov <dgutov@yandex.ru>
Wed, 4 Feb 2015 16:33:55 +0000 (18:33 +0200)
committerDmitry Gutov <dgutov@yandex.ru>
Wed, 4 Feb 2015 16:33:55 +0000 (18:33 +0200)
Fixes #294

company.el
test/frontends-tests.el

index 86d93c238b13c6193126cf84c514a3ea2361ae5a..af4671ecf1d2f8dec0d96273042572ab73c2c8f7 100644 (file)
@@ -5,7 +5,7 @@
 ;; Author: Nikolaj Schumacher
 ;; Maintainer: Dmitry Gutov <dgutov@yandex.ru>
 ;; URL: http://company-mode.github.io/
-;; Version: 0.8.10
+;; Version: 0.8.11
 ;; Keywords: abbrev, convenience, matching
 ;; Package-Requires: ((emacs "24.1") (cl-lib "0.5"))
 
@@ -2231,9 +2231,12 @@ If SHOW-VERSION is non-nil, show the version in the echo area."
                (string-match (regexp-quote company-search-string) value
                              (length company-prefix)))
           (let ((beg (+ margin (match-beginning 0)))
-                (end (+ margin (match-end 0))))
-            (add-text-properties beg end '(face company-tooltip-search)
-                                 line))
+                (end (+ margin (match-end 0)))
+                (width (- width (length right))))
+            (when (< beg width)
+              (add-text-properties beg (min end width)
+                                   '(face company-tooltip-search)
+                                   line)))
         (add-text-properties 0 width '(face company-tooltip-selection
                                        mouse-face company-tooltip-selection)
                              line)
index 35c94c95e52e7628198af0d89e5644bb6d68372c..613856e57418c2a7ee298b5ed786f3a3e7343800 100644 (file)
                      " MIRAI発売2カ月 ")
                    (company--create-lines 0 999)))))
 
+(ert-deftest company-fill-propertize-truncates-search-highlight ()
+  (let ((company-search-string "foo")
+        (company-backend #'ignore)
+        (company-prefix ""))
+    (should (equal-including-properties
+             (company-fill-propertize "barfoo" nil 6 t nil nil)
+             #("barfoo"
+               0 3 (face company-tooltip mouse-face company-tooltip-mouse)
+               3 6 (face company-tooltip-search mouse-face company-tooltip-mouse))))
+    (should (equal-including-properties
+             (company-fill-propertize "barfoo" nil 5 t "" " ")
+             #("barfo "
+               0 3 (face company-tooltip mouse-face company-tooltip-mouse)
+               3 5 (face company-tooltip-search mouse-face company-tooltip-mouse)
+               5 6 (face company-tooltip mouse-face company-tooltip-mouse))))
+    (should (equal-including-properties
+             (company-fill-propertize "barfoo" nil 3 t " " " ")
+             #(" bar "
+               0 5 (face company-tooltip mouse-face company-tooltip-mouse))))))
+
 (ert-deftest company-column-with-composition ()
   :tags '(interactive)
   (with-temp-buffer