QScintilla/Editor.py

changeset 6809
d1048e6db7f5
parent 6755
009812744917
child 6826
c6dda2cbe081
child 6842
c83dcb7c6147
equal deleted inserted replaced
6797:d9e56b0aa7ac 6809:d1048e6db7f5
4673 if self.isListActive(): 4673 if self.isListActive():
4674 self.cancelList() 4674 self.cancelList()
4675 4675
4676 if self.__completionListHookFunctions or \ 4676 if self.__completionListHookFunctions or \
4677 self.__completionListAsyncHookFunctions: 4677 self.__completionListAsyncHookFunctions:
4678 # Avoid delayed auto-completion after cursor repositioning
4679 self.__acText = self.__getAcText()
4678 if auto and Preferences.getEditor("AutoCompletionTimeout"): 4680 if auto and Preferences.getEditor("AutoCompletionTimeout"):
4679 self.__acTimer.stop() 4681 self.__acTimer.stop()
4680 self.__acContext = context 4682 self.__acContext = context
4681 self.__acTimer.start() 4683 self.__acTimer.start()
4682 else: 4684 else:
4684 elif not auto: 4686 elif not auto:
4685 self.autoCompleteQScintilla() 4687 self.autoCompleteQScintilla()
4686 elif self.autoCompletionSource() != QsciScintilla.AcsNone: 4688 elif self.autoCompletionSource() != QsciScintilla.AcsNone:
4687 self.autoCompleteQScintilla() 4689 self.autoCompleteQScintilla()
4688 4690
4691 def __getAcText(self):
4692 """
4693 Private method to get the text from cursor position for autocompleting.
4694
4695 @return text left of cursor position
4696 @rtype str
4697 """
4698 line, col = self.getCursorPosition()
4699 text = self.text(line)
4700 try:
4701 if self.__isStartChar(text[col - 1]):
4702 acText = self.getWordLeft(line, col - 1) + text[col - 1]
4703 else:
4704 acText = self.getWordLeft(line, col)
4705 except IndexError:
4706 acText = ""
4707
4708 return acText
4709
4689 def __autoComplete(self, auto=True, context=None): 4710 def __autoComplete(self, auto=True, context=None):
4690 """ 4711 """
4691 Private method to start auto-completion via plug-ins. 4712 Private method to start auto-completion via plug-ins.
4692 4713
4693 @keyparam auto flag indicating a call from the __charAdded method 4714 @keyparam auto flag indicating a call from the __charAdded method
4694 (boolean) 4715 (boolean)
4695 @keyparam context flag indicating to complete a context 4716 @keyparam context flag indicating to complete a context
4696 @type bool or None 4717 @type bool or None
4697 """ 4718 """
4698 line, col = self.getCursorPosition()
4699 text = self.text(line)
4700 try:
4701 if self.__isStartChar(text[col - 1]):
4702 self.__acText = self.getWordLeft(line, col - 1) + text[col - 1]
4703 else:
4704 self.__acText = self.getWordLeft(line, col)
4705 except IndexError:
4706 self.__acText = ""
4707
4708 self.__acCompletions.clear() 4719 self.__acCompletions.clear()
4709 self.__acCompletionsFinished = 0 4720 self.__acCompletionsFinished = 0
4710 4721
4711 # Suppress empty completions 4722 # Suppress empty completions
4712 if auto and self.__acText == '': 4723 if auto and self.__acText == '':
4746 @param completions list of possible completions 4757 @param completions list of possible completions
4747 @type list of str or set of str 4758 @type list of str or set of str
4748 @param acText text to be completed 4759 @param acText text to be completed
4749 @type str 4760 @type str
4750 """ 4761 """
4762 currentWord = self.__getAcText() or ' '
4751 # process the list only, if not already obsolete ... 4763 # process the list only, if not already obsolete ...
4752 if acText != self.__acText: 4764 if acText != self.__acText or not self.__acText.endswith(currentWord):
4765 # Suppress auto-completion done by QScintilla as fallback
4766 self.__acWatchdog.stop()
4753 return 4767 return
4754 4768
4755 self.__acCompletions.update(set(completions)) 4769 self.__acCompletions.update(set(completions))
4756 4770
4757 self.__acCompletionsFinished += 1 4771 self.__acCompletionsFinished += 1

eric ide

mercurial