emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master d8ca520 13/23: Improve search visualization


From: Dmitry Gutov
Subject: [elpa] master d8ca520 13/23: Improve search visualization
Date: Fri, 11 Nov 2016 22:21:42 +0000 (UTC)

branch: master
commit d8ca520e99f40db1a0d2727d9b46c1db26b81f12
Author: Andrea Orru <address@hidden>
Commit: Dmitry Gutov <address@hidden>

    Improve search visualization
    
    Fixes #567.
---
 NEWS.md                 |    1 +
 company.el              |   34 ++++++++++++++++++++--------------
 test/frontends-tests.el |   12 ++++++------
 3 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/NEWS.md b/NEWS.md
index ea04f48..ecb48f8 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,6 +2,7 @@
 
 ## Next
 
+* Better visualization of search matches. New face 
`company-tooltip-search-selection`.
 * New variable `company-files-exclusions`.
 * `company-next-page` and `company-previous-page` adhere to
   `company-selection-wrap-around` docstring more closely and only wrap around
diff --git a/company.el b/company.el
index d297bd3..d46e96a 100644
--- a/company.el
+++ b/company.el
@@ -118,9 +118,13 @@ attention to case differences."
   "Face used for the selection in the tooltip.")
 
 (defface company-tooltip-search
-  '((default :inherit company-tooltip-selection))
+  '((default :inherit highlight))
   "Face used for the search string in the tooltip.")
 
+(defface company-tooltip-search-selection
+  '((default :inherit highlight))
+  "Face used for the search string inside the selection in the tooltip.")
+
 (defface company-tooltip-mouse
   '((default :inherit highlight))
   "Face used for the tooltip item under the mouse.")
@@ -2475,22 +2479,24 @@ If SHOW-VERSION is non-nil, show the version in the 
echo area."
                                          'company-tooltip-common-selection
                                        'company-tooltip-common)
                                      line)
-    (when selected
-      (if (let ((re (funcall company-search-regexp-function
+    (when (let ((re (funcall company-search-regexp-function
                              company-search-string)))
             (and (not (string= re ""))
                  (string-match re value (length company-prefix))))
-          (pcase-dolist (`(,mbeg . ,mend) (company--search-chunks))
-            (let ((beg (+ margin mbeg))
-                  (end (+ margin mend))
-                  (width (- width (length right))))
-              (when (< beg width)
-                (font-lock-prepend-text-property beg (min end width)
-                                                 'face 'company-tooltip-search
-                                                 line))))
-        (font-lock-append-text-property 0 width 'face
-                                        'company-tooltip-selection
-                                        line)))
+      (pcase-dolist (`(,mbeg . ,mend) (company--search-chunks))
+        (let ((beg (+ margin mbeg))
+              (end (+ margin mend))
+              (width (- width (length right))))
+          (when (< beg width)
+            (font-lock-prepend-text-property beg (min end width) 'face
+                                             (if selected
+                                                 
'company-tooltip-search-selection
+                                               'company-tooltip-search)
+                                             line)))))
+    (when selected
+      (font-lock-append-text-property 0 width 'face
+                                      'company-tooltip-selection
+                                      line))
     (font-lock-append-text-property 0 width 'face
                                     'company-tooltip
                                     line)
diff --git a/test/frontends-tests.el b/test/frontends-tests.el
index 7b8ee61..9592bed 100644
--- a/test/frontends-tests.el
+++ b/test/frontends-tests.el
@@ -256,18 +256,18 @@
     (should (ert-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 company-tooltip) mouse-face 
(company-tooltip-mouse)))))
+               0 3 (face (company-tooltip-selection company-tooltip) 
mouse-face (company-tooltip-mouse))
+               3 6 (face (company-tooltip-search-selection 
company-tooltip-selection company-tooltip) mouse-face 
(company-tooltip-mouse)))))
     (should (ert-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 company-tooltip) mouse-face 
(company-tooltip-mouse))
-               5 6 (face (company-tooltip) mouse-face 
(company-tooltip-mouse)))))
+               0 3 (face (company-tooltip-selection company-tooltip) 
mouse-face (company-tooltip-mouse))
+               3 5 (face (company-tooltip-search-selection 
company-tooltip-selection company-tooltip) mouse-face (company-tooltip-mouse))
+               5 6 (face (company-tooltip-selection company-tooltip) 
mouse-face (company-tooltip-mouse)))))
     (should (ert-equal-including-properties
              (company-fill-propertize "barfoo" nil 3 t " " " ")
              #(" bar "
-               0 5 (face (company-tooltip) mouse-face 
(company-tooltip-mouse)))))))
+               0 5 (face (company-tooltip-selection company-tooltip) 
mouse-face (company-tooltip-mouse)))))))
 
 (ert-deftest company-fill-propertize-overrides-face-property ()
   (let ((company-backend #'ignore)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]