Squish: Ensure text cursor has safe position

When re-opening a file that had been opened and closed inside
the current active session we open the file at the last used
editor position.
Provide a function to explicitly jump to the first line of an
editor.

Change-Id: I0602d8ef46e80a20385fd1b205812776d6666326
Reviewed-by: Robert Loehning <robert.loehning@qt.io>
This commit is contained in:
Christian Stenger
2018-11-02 09:47:38 +01:00
parent 42ced7ac94
commit 6cdcae528d
3 changed files with 8 additions and 9 deletions

View File

@@ -23,6 +23,10 @@
#
############################################################################
def jumpToFirstLine(editor):
home = "<Home>" if platform.system() == 'Darwin' else "<Ctrl+Home>"
type(editor, home)
# places the cursor inside the given editor into the given line
# (leading and trailing whitespaces are ignored!)
# and goes to the end of the line
@@ -36,10 +40,7 @@ def placeCursorToLine(editor, line, isRegex=False):
if not isinstance(editor, (str, unicode)):
editor = objectMap.realName(editor)
oldPosition = 0
if isDarwin:
type(getEditor(), "<Home>")
else:
type(getEditor(), "<Ctrl+Home>")
jumpToFirstLine(getEditor())
found = False
if isRegex:
regex = re.compile(line)

View File

@@ -85,10 +85,7 @@ def main():
if not waitFor("str(mainWin.windowTitle).startswith('dummy.cpp ') and ' @ cplusplus-tools ' in str(mainWin.windowTitle)", 5000):
test.warning("Opening dummy.cpp seems to have failed")
# Reset cursor to the start of the document
if platform.system() == 'Darwin':
type(cppwindow, "<Home>")
else:
type(cppwindow, "<Ctrl+Home>")
jumpToFirstLine(cppwindow)
type(cppwindow, "<Ctrl+f>")
clickButton(waitForObject(":*Qt Creator_Utils::IconButton"))

View File

@@ -76,7 +76,7 @@ def pasteFile(sourceFile, protocol):
invokeMenuItem("File", "Open File or Project...")
selectFromFileDialog(sourceFile)
editor = waitForObject(":Qt Creator_CppEditor::Internal::CPPEditorWidget")
type(editor, "<Up>")
jumpToFirstLine(editor)
typeLines(editor, "// tst_codepasting %s" % datetime.utcnow())
sourceText = editor.plainText
invokeMenuItem("Tools", "Code Pasting", "Paste Snippet...")
@@ -232,6 +232,7 @@ def main():
invokeMenuItem("File", "Open File or Project...")
selectFromFileDialog(sourceFile)
editor = waitForObject(":Qt Creator_CppEditor::Internal::CPPEditorWidget")
jumpToFirstLine(editor)
markText(editor, "Down", 7)
# QString QTextCursor::selectedText () const:
# "Note: If the selection obtained from an editor spans a line break, the text will contain a