forked from qt-creator/qt-creator
Squish: Stabilize placeCursorToLine() on Mac
Change-Id: I3a3292b8576fe36107335e07e9f125fbd1478b80 Reviewed-by: Robert Loehning <robert.loehning@digia.com>
This commit is contained in:
@@ -6,28 +6,36 @@ import re;
|
|||||||
# 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()
|
def getEditor():
|
||||||
|
return waitForObject(editor)
|
||||||
|
|
||||||
|
isDarwin = platform.system() == 'Darwin'
|
||||||
|
if not isinstance(editor, (str, unicode)):
|
||||||
|
editor = objectMap.realName(editor)
|
||||||
oldPosition = 0
|
oldPosition = 0
|
||||||
cursor.setPosition(oldPosition)
|
if isDarwin:
|
||||||
editor.setTextCursor(cursor)
|
type(getEditor(), "<Home>")
|
||||||
|
else:
|
||||||
|
type(getEditor(), "<Ctrl+Home>")
|
||||||
found = False
|
found = False
|
||||||
if isRegex:
|
if isRegex:
|
||||||
regex = re.compile(line)
|
regex = re.compile(line)
|
||||||
while not found:
|
while not found:
|
||||||
currentLine = str(lineUnderCursor(editor)).strip()
|
currentLine = str(lineUnderCursor(getEditor())).strip()
|
||||||
found = isRegex and regex.match(currentLine) or not isRegex and currentLine == line
|
found = isRegex and regex.match(currentLine) or not isRegex and currentLine == line
|
||||||
if not found:
|
if not found:
|
||||||
type(editor, "<Down>")
|
type(getEditor(), "<Down>")
|
||||||
newPosition = editor.textCursor().position()
|
newPosition = getEditor().textCursor().position()
|
||||||
if oldPosition == newPosition:
|
if oldPosition == newPosition:
|
||||||
break
|
break
|
||||||
oldPosition = newPosition
|
oldPosition = newPosition
|
||||||
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()
|
if isDarwin:
|
||||||
cursor.movePosition(QTextCursor.EndOfLine, QTextCursor.MoveAnchor)
|
type(getEditor(), "<Ctrl+Right>")
|
||||||
editor.setTextCursor(cursor)
|
else:
|
||||||
|
type(getEditor(), "<End>")
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# this function returns True if a QMenu is
|
# this function returns True if a QMenu is
|
||||||
|
|||||||
Reference in New Issue
Block a user