--- a/QScintilla/Editor.py Sat Feb 16 10:27:50 2019 +0100 +++ b/QScintilla/Editor.py Sat Mar 02 11:15:24 2019 +0100 @@ -397,6 +397,8 @@ size=Preferences.getEditor("AutoCompletionCacheSize")) self.__acCache.setMaximumCacheTime( Preferences.getEditor("AutoCompletionCacheTime")) + self.__acCacheEnabled = Preferences.getEditor( + "AutoCompletionCacheEnabled") self.__acTimer = QTimer(self) self.__acTimer.setSingleShot(True) self.__acTimer.setInterval( @@ -611,23 +613,17 @@ elif line0.startswith("\\documentclass"): bindName = "dummy.tex" - # check filetype if not bindName and self.filetype: - if self.filetype in ["Python", "Python2"]: - bindName = "dummy.py" - elif self.filetype == "Python3": + # check filetype + from . import Lexers + supportedLanguages = Lexers.getSupportedLanguages() + if self.filetype in supportedLanguages: + bindName = supportedLanguages[self.filetype][1] + elif self.filetype in ["Python", "Python2", "Python3"]: bindName = "dummy.py" - elif self.filetype == "Ruby": - bindName = "dummy.rb" - elif self.filetype == "D": - bindName = "dummy.d" - elif self.filetype == "Properties": - bindName = "dummy.ini" - elif self.filetype == "JavaScript": - bindName = "dummy.js" - - # #! marker detection + if not bindName and line0.startswith("#!"): + # #! marker detection if "python3" in line0: bindName = "dummy.py" self.filetype = "Python3" @@ -3295,9 +3291,9 @@ @param modifiers keyboard modifiers (Qt.KeyboardModifiers) """ if margin == self.__bmMargin: - self.toggleBookmark(line + 1) + self.toggleBookmark(line + 1) elif margin == self.__bpMargin: - self.__toggleBreakpoint(line + 1) + self.__toggleBreakpoint(line + 1) elif margin == self.__indicMargin: if self.markersAtLine(line) & (1 << self.syntaxerror): self.__showSyntaxError(line) @@ -4109,6 +4105,8 @@ Preferences.getEditor("AutoCompletionCacheSize")) self.__acCache.setMaximumCacheTime( Preferences.getEditor("AutoCompletionCacheTime")) + self.__acCacheEnabled = Preferences.getEditor( + "AutoCompletionCacheEnabled") acTimeout = Preferences.getEditor("AutoCompletionTimeout") if acTimeout != self.__acTimer.interval: self.__acTimer.setInterval(acTimeout) @@ -4677,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 @@ -4688,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. @@ -4697,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 @@ -4714,7 +4723,10 @@ if auto and self.__acText == '': return - completions = self.__acCache.get(self.__acText) + if self.__acCacheEnabled: + completions = self.__acCache.get(self.__acText) + else: + completions = None if completions is not None: # show list with cached entries if self.isListActive(): @@ -4747,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)) @@ -4775,7 +4790,8 @@ self.cancelList() if self.__acCompletions: - self.__acCache.add(acText, set(self.__acCompletions)) + if self.__acCacheEnabled: + self.__acCache.add(acText, set(self.__acCompletions)) self.__showCompletionsList(self.__acCompletions) def __showCompletionsList(self, completions):