def word_start_cursor(self): """ Start of the word to the left of the current text cursor. If a sequence of non-word characters precedes the first word, skip over them. (This emulates the behavior of bash, emacs, etc.) """ cursor = self.textCursor() position = cursor.position() position -= 1 while position >= 0 and not is_letter_or_number(self.document().characterAt(position)): position -= 1 while position >= 0 and is_letter_or_number(self.document().characterAt(position)): position -= 1 cursor.setPosition(position + 1) return cursor
def word_end_cursor(self): """ End of the word to the right the current text cursor. If a sequence of non-word characters precedes the first word, skip over them. (This emulates the behavior of bash, emacs, etc.) """ cursor = self.textCursor() position = cursor.position() cursor.movePosition(QtGui.QTextCursor.End) end = cursor.position() while position < end and not is_letter_or_number(self.document().characterAt(position)): position += 1 while position < end and is_letter_or_number(self.document().characterAt(position)): position += 1 cursor = self.textCursor() cursor.setPosition(position) return cursor