--- a/src/eric7/QScintilla/Editor.py Mon Nov 27 10:24:47 2023 +0100 +++ b/src/eric7/QScintilla/Editor.py Mon Nov 27 14:45:11 2023 +0100 @@ -3861,23 +3861,31 @@ self.setMonospaced(False) self.__setMarginsDisplay() - def getWordBoundaries(self, line, index, useWordChars=True): + def getWordBoundaries(self, line, index, useWordChars=True, forCompletion=False): """ Public method to get the word boundaries at a position. - @param line number of line to look at (int) - @param index position to look at (int) + @param line number of line to look at + @type int + @param index position to look at + @type int @param useWordChars flag indicating to use the wordCharacters - method (boolean) + method (defaults to True) + @type bool (optional) + @param forCompletion flag indicating a modification for completions (defaults + to False) + @type bool (optional) @return tuple with start and end indexes of the word at the position - (integer, integer) + @rtype tuple of (int, int) """ wc = self.wordCharacters() if wc is None or not useWordChars: - pattern = r"\b[\w_]+\b=?" + pattern = r"\b[\w_]+\b" else: wc = re.sub(r"\w", "", wc) - pattern = r"\b[\w{0}]+\b=?".format(re.escape(wc)) + pattern = r"\b[\w{0}]+\b".format(re.escape(wc)) + if forCompletion: + pattern += "=?" rx = ( re.compile(pattern) if self.caseSensitive() @@ -3892,19 +3900,29 @@ return (index, index) - def getWord(self, line, index, direction=0, useWordChars=True): + def getWord(self, line, index, direction=0, useWordChars=True, forCompletion=False): """ Public method to get the word at a position. - @param line number of line to look at (int) - @param index position to look at (int) + @param line number of line to look at + @type int + @param index position to look at + @type int @param direction direction to look in (0 = whole word, 1 = left, 2 = right) + @type int @param useWordChars flag indicating to use the wordCharacters - method (boolean) - @return the word at that position (string) - """ - start, end = self.getWordBoundaries(line, index, useWordChars) + method (defaults to True) + @type bool (optional) + @param forCompletion flag indicating a modification for completions (defaults + to False) + @type bool (optional) + @return the word at that position + @rtype str + """ + start, end = self.getWordBoundaries( + line, index, useWordChars=useWordChars, forCompletion=forCompletion + ) if direction == 1: end = index elif direction == 2: @@ -5586,7 +5604,7 @@ line, col = self.getCursorPosition() else: line, col = self.getCursorPosition() - wLeft = self.getWordLeft(line, col) + wLeft = self.getWord(line, col, 1, forCompletion=True) # word left if not txt.startswith(wLeft): self.selectCurrentWord() self.removeSelectedText()