branch: externals/company
commit b7120176b8107048a32e9083e48acd8abec2c20c
Author: Dmitry Gutov <dgu...@yandex.ru>
Commit: Dmitry Gutov <dgu...@yandex.ru>

    company-preview-frontend: Fix an "args out of range" error
    
    #1116
    
    Which happens when company-preview-frontend is used directly, and the new 
prefix
    can be longer than the previous selected completion.
---
 company.el | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/company.el b/company.el
index 3b5a7ba..af61696 100644
--- a/company.el
+++ b/company.el
@@ -3482,11 +3482,15 @@ Delay is determined by `company-tooltip-idle-delay'."
     (`pre-command (company-preview-hide))
     (`unhide
      (when company-selection
-       (let ((company-prefix (buffer-substring
-                              (- company-point (length company-prefix))
-                              (point))))
-         (company-preview-show-at-point (point)
-                                        (nth company-selection 
company-candidates)))))
+       (let* ((current (nth company-selection company-candidates))
+              (company-prefix (if (equal current company-prefix)
+                                  ;; Would be more accurate to compare lengths,
+                                  ;; but this is shorter.
+                                  current
+                                (buffer-substring
+                                 (- company-point (length company-prefix))
+                                 (point)))))
+         (company-preview-show-at-point (point) current))))
     (`post-command
      (when company-selection
        (company-preview-show-at-point (point)

Reply via email to