Squish: Simplified placeCursorToLine

Change-Id: Ib56bc7b2596ac61233e147fb62f763a594abe9df
Reviewed-by: Christian Stenger <christian.stenger@nokia.com>
This commit is contained in:
Robert Loehning
2012-05-23 15:36:30 +02:00
committed by Robert Löhning
parent a71b768675
commit 53fb9d4ae8

View File

@@ -5,7 +5,7 @@ import re;
# and goes to the end of the line # and goes to the end of the line
# line can be a regex - but if so, remember to set isRegex to True # 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 # 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() cursor = editor.textCursor()
oldPosition = 0 oldPosition = 0
cursor.setPosition(oldPosition) cursor.setPosition(oldPosition)
@@ -15,26 +15,17 @@ def placeCursorToLine(editor,line,isRegex=False):
regex = re.compile(line) regex = re.compile(line)
while not found: while not found:
currentLine = str(lineUnderCursor(editor)).strip() currentLine = str(lineUnderCursor(editor)).strip()
if isRegex: found = isRegex and regex.match(currentLine) or not isRegex and currentLine == line
if regex.match(currentLine): if not found:
found = True type(editor, "<Down>")
else: newPosition = editor.textCursor().position()
moveTextCursor(editor, QTextCursor.Down, QTextCursor.MoveAnchor) if oldPosition == newPosition:
if oldPosition==editor.textCursor().position(): break
break oldPosition = newPosition
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()
if not found: if not found:
test.fatal("Couldn't find line matching\n\n%s\n\nLeaving test..." % line) test.fatal("Couldn't find line matching\n\n%s\n\nLeaving test..." % line)
return False return False
cursor=editor.textCursor() cursor = editor.textCursor()
cursor.movePosition(QTextCursor.EndOfLine, QTextCursor.MoveAnchor) cursor.movePosition(QTextCursor.EndOfLine, QTextCursor.MoveAnchor)
editor.setTextCursor(cursor) editor.setTextCursor(cursor)
return True return True