From 3a0a1eebe2be8f71c9541ed11a8bd79343cedb7e Mon Sep 17 00:00:00 2001 From: Dmitry Gutov Date: Mon, 25 Mar 2013 11:39:46 +0400 Subject: [PATCH] company-pseudo-tooltip-frontend: Redraw when diplaced --- NEWS.md | 1 + company-tests.el | 18 ++++++++++++++++++ company.el | 13 +++++++++++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/NEWS.md b/NEWS.md index fc1ffc27c..cc2175561 100644 --- 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) diff --git a/company-tests.el b/company-tests.el index ee477e7c5..55675c95b 100644 --- a/company-tests.el +++ b/company-tests.el @@ -152,3 +152,21 @@ (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))))))) diff --git a/company.el b/company.el index 0d33ad38c..078400f21 100644 --- a/company.el +++ b/company.el @@ -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)) -- 2.39.2