eric6/QScintilla/Editor.py

changeset 8259
2bbec88047dd
parent 8258
82b608e352ec
child 8273
698ae46f40a4
child 8276
1436fd09d1e1
equal deleted inserted replaced
8258:82b608e352ec 8259:2bbec88047dd
1802 self.__setMarginsDisplay() 1802 self.__setMarginsDisplay()
1803 if self.lexer_.lexer() == "container" or self.lexer_.lexer() is None: 1803 if self.lexer_.lexer() == "container" or self.lexer_.lexer() is None:
1804 self.SCN_STYLENEEDED.connect(self.__styleNeeded) 1804 self.SCN_STYLENEEDED.connect(self.__styleNeeded)
1805 1805
1806 # get the font for style 0 and set it as the default font 1806 # get the font for style 0 and set it as the default font
1807 if pyname and pyname.startswith("Pygments|"): 1807 key = (
1808 key = 'Scintilla/Guessed/style0/font' 1808 'Scintilla/Guessed/style0/font'
1809 else: 1809 if pyname and pyname.startswith("Pygments|") else
1810 key = 'Scintilla/{0}/style0/font'.format(self.lexer_.language()) 1810 'Scintilla/{0}/style0/font'.format(self.lexer_.language())
1811 )
1811 fdesc = Preferences.Prefs.settings.value(key) 1812 fdesc = Preferences.Prefs.settings.value(key)
1812 if fdesc is not None: 1813 if fdesc is not None:
1813 font = QFont(fdesc[0], int(fdesc[1])) 1814 font = QFont(fdesc[0], int(fdesc[1]))
1814 self.lexer_.setDefaultFont(font) 1815 self.lexer_.setDefaultFont(font)
1815 self.lexer_.readSettings(Preferences.Prefs.settings, "Scintilla") 1816 self.lexer_.readSettings(Preferences.Prefs.settings, "Scintilla")
1818 1819
1819 # now set the lexer properties 1820 # now set the lexer properties
1820 self.lexer_.initProperties() 1821 self.lexer_.initProperties()
1821 1822
1822 # initialize the lexer APIs settings 1823 # initialize the lexer APIs settings
1823 if self.project.isOpen() and self.project.isProjectFile(filename): 1824 projectType = (
1824 projectType = self.project.getProjectType() 1825 self.project.getProjectType()
1825 else: 1826 if self.project.isOpen() and self.project.isProjectFile(filename)
1826 projectType = "" 1827 else ""
1828 )
1827 api = self.vm.getAPIsManager().getAPIs(self.apiLanguage, 1829 api = self.vm.getAPIsManager().getAPIs(self.apiLanguage,
1828 projectType=projectType) 1830 projectType=projectType)
1829 if api is not None and not api.isEmpty(): 1831 if api is not None and not api.isEmpty():
1830 self.lexer_.setAPIs(api.getQsciAPIs()) 1832 self.lexer_.setAPIs(api.getQsciAPIs())
1831 self.acAPI = True 1833 self.acAPI = True
3565 if wc is None or not useWordChars: 3567 if wc is None or not useWordChars:
3566 pattern = r"\b[\w_]+\b" 3568 pattern = r"\b[\w_]+\b"
3567 else: 3569 else:
3568 wc = re.sub(r'\w', "", wc) 3570 wc = re.sub(r'\w', "", wc)
3569 pattern = r"\b[\w{0}]+\b".format(re.escape(wc)) 3571 pattern = r"\b[\w{0}]+\b".format(re.escape(wc))
3570 if self.caseSensitive(): 3572 rx = (
3571 rx = re.compile(pattern) 3573 re.compile(pattern)
3572 else: 3574 if self.caseSensitive() else
3573 rx = re.compile(pattern, re.IGNORECASE) 3575 re.compile(pattern, re.IGNORECASE)
3576 )
3574 3577
3575 text = self.text(line) 3578 text = self.text(line)
3576 for match in rx.finditer(text): 3579 for match in rx.finditer(text):
3577 start, end = match.span() 3580 start, end = match.span()
3578 if start <= index <= end: 3581 if start <= index <= end:
5023 @rtype str 5026 @rtype str
5024 """ 5027 """
5025 line, col = self.getCursorPosition() 5028 line, col = self.getCursorPosition()
5026 text = self.text(line) 5029 text = self.text(line)
5027 try: 5030 try:
5028 if self.__isStartChar(text[col - 1]): 5031 acText = (
5029 acText = self.getWordLeft(line, col - 1) + text[col - 1] 5032 self.getWordLeft(line, col - 1) + text[col - 1]
5030 else: 5033 if self.__isStartChar(text[col - 1]) else
5031 acText = self.getWordLeft(line, col) 5034 self.getWordLeft(line, col)
5035 )
5032 except IndexError: 5036 except IndexError:
5033 acText = "" 5037 acText = ""
5034 5038
5035 return acText 5039 return acText
5036 5040
5048 5052
5049 # Suppress empty completions 5053 # Suppress empty completions
5050 if auto and self.__acText == '': 5054 if auto and self.__acText == '':
5051 return 5055 return
5052 5056
5053 if self.__acCacheEnabled: 5057 completions = (
5054 completions = self.__acCache.get(self.__acText) 5058 self.__acCache.get(self.__acText)
5055 else: 5059 if self.__acCacheEnabled else
5056 completions = None 5060 None
5061 )
5057 if completions is not None: 5062 if completions is not None:
5058 # show list with cached entries 5063 # show list with cached entries
5059 if self.isListActive(): 5064 if self.isListActive():
5060 self.cancelList() 5065 self.cancelList()
5061 5066
5128 Private method to show the completions list. 5133 Private method to show the completions list.
5129 5134
5130 @param completions completions to be shown 5135 @param completions completions to be shown
5131 @type list of str or set of str 5136 @type list of str or set of str
5132 """ 5137 """
5133 if Preferences.getEditor("AutoCompletionReversedList"): 5138 acCompletions = (
5134 acCompletions = sorted( 5139 sorted(
5135 list(completions), 5140 list(completions),
5136 key=self.__replaceLeadingUnderscores) 5141 key=self.__replaceLeadingUnderscores)
5137 else: 5142 if Preferences.getEditor("AutoCompletionReversedList") else
5138 acCompletions = sorted(list(completions)) 5143 sorted(list(completions))
5144 )
5139 self.showUserList(EditorAutoCompletionListID, acCompletions) 5145 self.showUserList(EditorAutoCompletionListID, acCompletions)
5140 5146
5141 def __replaceLeadingUnderscores(self, txt): 5147 def __replaceLeadingUnderscores(self, txt):
5142 """ 5148 """
5143 Private method to replace the first two underlines for invers sorting. 5149 Private method to replace the first two underlines for invers sorting.
5336 shift = ct.index("(") 5342 shift = ct.index("(")
5337 if ctshift < shift: 5343 if ctshift < shift:
5338 ctshift = shift 5344 ctshift = shift
5339 5345
5340 cv = self.callTipsVisible() 5346 cv = self.callTipsVisible()
5341 if cv > 0: 5347 ct = (
5342 # this is just a safe guard 5348 # this is just a safe guard
5343 ct = self._encodeString("\n".join(callTips[:cv])) 5349 self._encodeString("\n".join(callTips[:cv]))
5344 else: 5350 if cv > 0 else
5345 # until here and unindent below 5351 # until here and unindent below
5346 ct = self._encodeString("\n".join(callTips)) 5352 self._encodeString("\n".join(callTips))
5353 )
5347 5354
5348 self.SendScintilla(QsciScintilla.SCI_CALLTIPSHOW, 5355 self.SendScintilla(QsciScintilla.SCI_CALLTIPSHOW,
5349 self.__adjustedCallTipPosition(ctshift, pos), ct) 5356 self.__adjustedCallTipPosition(ctshift, pos), ct)
5350 if b'\n' in ct: 5357 if b'\n' in ct:
5351 return 5358 return

eric ide

mercurial