forked from qt-creator/qt-creator
Squish: Simplified placeCursorToLine
Change-Id: Ib56bc7b2596ac61233e147fb62f763a594abe9df Reviewed-by: Christian Stenger <christian.stenger@nokia.com>
This commit is contained in:
committed by
Robert Löhning
parent
a71b768675
commit
53fb9d4ae8
@@ -5,7 +5,7 @@ import re;
|
||||
# and goes to the end of the line
|
||||
# line can be a regex - but if so, remember to set isRegex to True
|
||||
# the function returns True if this went fine, False on error
|
||||
def placeCursorToLine(editor,line,isRegex=False):
|
||||
def placeCursorToLine(editor, line, isRegex=False):
|
||||
cursor = editor.textCursor()
|
||||
oldPosition = 0
|
||||
cursor.setPosition(oldPosition)
|
||||
@@ -15,26 +15,17 @@ def placeCursorToLine(editor,line,isRegex=False):
|
||||
regex = re.compile(line)
|
||||
while not found:
|
||||
currentLine = str(lineUnderCursor(editor)).strip()
|
||||
if isRegex:
|
||||
if regex.match(currentLine):
|
||||
found = True
|
||||
else:
|
||||
moveTextCursor(editor, QTextCursor.Down, QTextCursor.MoveAnchor)
|
||||
if oldPosition==editor.textCursor().position():
|
||||
break
|
||||
oldPosition = editor.textCursor().position()
|
||||
else:
|
||||
if currentLine==line:
|
||||
found = True
|
||||
else:
|
||||
moveTextCursor(editor, QTextCursor.Down, QTextCursor.MoveAnchor)
|
||||
if oldPosition==editor.textCursor().position():
|
||||
break
|
||||
oldPosition = editor.textCursor().position()
|
||||
found = isRegex and regex.match(currentLine) or not isRegex and currentLine == line
|
||||
if not found:
|
||||
type(editor, "<Down>")
|
||||
newPosition = editor.textCursor().position()
|
||||
if oldPosition == newPosition:
|
||||
break
|
||||
oldPosition = newPosition
|
||||
if not found:
|
||||
test.fatal("Couldn't find line matching\n\n%s\n\nLeaving test..." % line)
|
||||
return False
|
||||
cursor=editor.textCursor()
|
||||
cursor = editor.textCursor()
|
||||
cursor.movePosition(QTextCursor.EndOfLine, QTextCursor.MoveAnchor)
|
||||
editor.setTextCursor(cursor)
|
||||
return True
|
||||
|
Reference in New Issue
Block a user