]> code.delx.au - gnu-emacs-elpa/commitdiff
company-pseudo-tooltip-frontend: Redraw when diplaced
authorDmitry Gutov <dgutov@yandex.ru>
Mon, 25 Mar 2013 07:39:46 +0000 (11:39 +0400)
committerDmitry Gutov <dgutov@yandex.ru>
Mon, 25 Mar 2013 09:55:07 +0000 (13:55 +0400)
NEWS.md
company-tests.el
company.el

diff --git a/NEWS.md b/NEWS.md
index fc1ffc27c10728005fb994b73076304391722ced..cc2175561974697f93c5fa63ba218bf39b51f2c1 100644 (file)
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,6 +2,7 @@
 
 ## Next
 
+* Pseudo-tooltip stays up-to-date when text is inserted after the point.
 * Fixed `company-require-match` mechanics.
 
 ## 2013-03-24 (0.6.2)
index ee477e7c5940ecb1890c88b9dee1b33f5cd3c61c..55675c95b4faee83d408606caac721abd2a18b78 100644 (file)
         (self-insert-command 1))
       (company-post-command)
       (should (string= "ab " (buffer-string))))))
+
+(ert-deftest company-pseudo-tooltip-does-not-get-displaced ()
+  (with-temp-buffer
+    (save-window-excursion
+      (set-window-buffer nil (current-buffer))
+      (save-excursion (insert " ff"))
+      (company-mode)
+      (let ((company-frontends '(company-pseudo-tooltip-frontend))
+            (company-begin-commands '(self-insert-command))
+            (company-backends
+             (list (lambda (c &optional arg)
+                     (case c (prefix "") (candidates '("a" "b" "c")))))))
+        (let (this-command)
+          (company-complete))
+        (company-post-command)
+        (open-line 1)
+        (company-post-command)
+        (should (eq 2 (overlay-start company-pseudo-tooltip-overlay)))))))
index 0d33ad38c1d427fc5cbbd1e726d4869dadc19169..078400f21ae8458f056c238b1ad886e0f24cf6f1 100644 (file)
@@ -1817,6 +1817,10 @@ Returns a negative number if the tooltip should be displayed above point."
                  (overlay-get company-pseudo-tooltip-overlay 'company-before))
     (overlay-put company-pseudo-tooltip-overlay 'window (selected-window))))
 
+(defun company-pseudo-tooltip-guard ()
+  (buffer-substring-no-properties
+   (point) (overlay-start company-pseudo-tooltip-overlay)))
+
 (defun company-pseudo-tooltip-frontend (command)
   "A `company-mode' front-end similar to a tool-tip but based on overlays."
   (case command
@@ -1828,10 +1832,15 @@ Returns a negative number if the tooltip should be displayed above point."
                          0))
            (new-height (company--pseudo-tooltip-height)))
        (unless (and (>= (* old-height new-height) 0)
-                    (>= (abs old-height) (abs new-height)))
+                    (>= (abs old-height) (abs new-height))
+                    (equal (company-pseudo-tooltip-guard)
+                           (overlay-get company-pseudo-tooltip-overlay
+                                        'company-guard)))
          ;; Redraw needed.
          (company-pseudo-tooltip-show-at-point (- (point)
-                                                  (length company-prefix)))))
+                                                  (length company-prefix)))
+         (overlay-put company-pseudo-tooltip-overlay
+                      'company-guard (company-pseudo-tooltip-guard))))
      (company-pseudo-tooltip-unhide))
     (hide (company-pseudo-tooltip-hide)
           (setq company-tooltip-offset 0))