QScintilla/Editor.py

changeset 6809
d1048e6db7f5
parent 6755
009812744917
child 6826
c6dda2cbe081
child 6842
c83dcb7c6147
--- a/QScintilla/Editor.py	Sat Feb 23 13:05:18 2019 +0100
+++ b/QScintilla/Editor.py	Sat Feb 23 13:30:36 2019 +0100
@@ -4675,6 +4675,8 @@
         
         if self.__completionListHookFunctions or \
            self.__completionListAsyncHookFunctions:
+            # Avoid delayed auto-completion after cursor repositioning
+            self.__acText = self.__getAcText()
             if auto and Preferences.getEditor("AutoCompletionTimeout"):
                 self.__acTimer.stop()
                 self.__acContext = context
@@ -4686,6 +4688,25 @@
         elif self.autoCompletionSource() != QsciScintilla.AcsNone:
             self.autoCompleteQScintilla()
     
+    def __getAcText(self):
+        """
+        Private method to get the text from cursor position for autocompleting.
+        
+        @return text left of cursor position
+        @rtype str
+        """
+        line, col = self.getCursorPosition()
+        text = self.text(line)
+        try:
+            if self.__isStartChar(text[col - 1]):
+                acText = self.getWordLeft(line, col - 1) + text[col - 1]
+            else:
+                acText = self.getWordLeft(line, col)
+        except IndexError:
+            acText = ""
+        
+        return acText
+    
     def __autoComplete(self, auto=True, context=None):
         """
         Private method to start auto-completion via plug-ins.
@@ -4695,16 +4716,6 @@
         @keyparam context flag indicating to complete a context
         @type bool or None
         """
-        line, col = self.getCursorPosition()
-        text = self.text(line)
-        try:
-            if self.__isStartChar(text[col - 1]):
-                self.__acText = self.getWordLeft(line, col - 1) + text[col - 1]
-            else:
-                self.__acText = self.getWordLeft(line, col)
-        except IndexError:
-            self.__acText = ""
-        
         self.__acCompletions.clear()
         self.__acCompletionsFinished = 0
         
@@ -4748,8 +4759,11 @@
         @param acText text to be completed
         @type str
         """
+        currentWord = self.__getAcText() or ' '
         # process the list only, if not already obsolete ...
-        if acText != self.__acText:
+        if acText != self.__acText or not self.__acText.endswith(currentWord):
+            # Suppress auto-completion done by QScintilla as fallback
+            self.__acWatchdog.stop()
             return
         
         self.__acCompletions.update(set(completions))

eric ide

mercurial