QScintilla/Editor.py

changeset 2213
022f4ad3ed19
parent 2189
5149cec53130
child 2216
3372cf8877c0
equal deleted inserted replaced
2212:87d664204684 2213:022f4ad3ed19
2962 2962
2963 @param line number of line to look at (int) 2963 @param line number of line to look at (int)
2964 @param index position to look at (int) 2964 @param index position to look at (int)
2965 @keyparam useWordChars flag indicating to use the wordCharacters 2965 @keyparam useWordChars flag indicating to use the wordCharacters
2966 method (boolean) 2966 method (boolean)
2967 @return tuple with start and end indices of the word at the position 2967 @return tuple with start and end indexes of the word at the position
2968 (integer, integer) 2968 (integer, integer)
2969 """ 2969 """
2970 text = self.text(line) 2970 text = self.text(line)
2971 if self.caseSensitive(): 2971 if self.caseSensitive():
2972 cs = Qt.CaseSensitive 2972 cs = Qt.CaseSensitive
3039 3039
3040 @return the word at that current position (string) 3040 @return the word at that current position (string)
3041 """ 3041 """
3042 line, index = self.getCursorPosition() 3042 line, index = self.getCursorPosition()
3043 return self.getWord(line, index) 3043 return self.getWord(line, index)
3044
3045 def getCurrentWordBoundaries(self):
3046 """
3047 Public method to get the word boundaries at the current position.
3048
3049 @return tuple with start and end indexes of the current word
3050 (integer, integer)
3051 """
3052 line, index = self.getCursorPosition()
3053 return self.getWordBoundaries(line, index)
3044 3054
3045 def selectWord(self, line, index): 3055 def selectWord(self, line, index):
3046 """ 3056 """
3047 Public method to select the word at a position. 3057 Public method to select the word at a position.
3048 3058
6638 while self.__receivedWhileSyncing: 6648 while self.__receivedWhileSyncing:
6639 command = self.__receivedWhileSyncing.pop(0) 6649 command = self.__receivedWhileSyncing.pop(0)
6640 self.__dispatchCommand(command) 6650 self.__dispatchCommand(command)
6641 6651
6642 self.__isSyncing = False 6652 self.__isSyncing = False
6653
6654 #######################################################################
6655 ## Special search related methods
6656 #######################################################################
6657
6658 def searchCurrentWordForward(self):
6659 """
6660 Public slot to search the current word forward.
6661 """
6662 self.__searchCurrentWord(forward=True)
6663
6664 def searchCurrentWordBackward(self):
6665 """
6666 Public slot to search the current word backward.
6667 """
6668 self.__searchCurrentWord(forward=False)
6669
6670 def __searchCurrentWord(self, forward=True):
6671 """
6672 Public slot to search the next occurrence of the current word.
6673
6674 @param forward flag indicating the search direction (boolean)
6675 """
6676 line, index = self.getCursorPosition()
6677 word = self.getCurrentWord()
6678 wordStart, wordEnd = self.getCurrentWordBoundaries()
6679 wordStartPos = self.positionFromLineIndex(line, wordStart)
6680 wordEndPos = self.positionFromLineIndex(line, wordEnd)
6681
6682 print(word, wordStartPos, wordEndPos, "<"+self.text()[wordStartPos:wordEndPos]+">")
6683
6684 regExp = re.compile(r"\b{0}\b".format(word))
6685 if forward:
6686 startPos = wordEndPos
6687 else:
6688 startPos = wordStartPos
6689
6690 matches = [m for m in regExp.finditer(self.text())]
6691 if matches:
6692 if forward:
6693 matchesAfter = [m for m in matches if m.start() >= startPos]
6694 if matchesAfter:
6695 match = matchesAfter[0]
6696 else:
6697 # wrap around
6698 match = matches[0]
6699 else:
6700 matchesBefore = [m for m in matches if m.start() < startPos]
6701 if matchesBefore:
6702 match = matchesBefore[-1]
6703 else:
6704 # wrap around
6705 match = matches[-1]
6706 line, index = self.lineIndexFromPosition(match.start())
6707 self.setSelection(line, index + len(match.group(0)), line, index)

eric ide

mercurial