From 6cdcae528dc72c8deab0ad60630242142fd3ab5d Mon Sep 17 00:00:00 2001 From: Christian Stenger Date: Fri, 2 Nov 2018 09:47:38 +0100 Subject: [PATCH] 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 --- tests/system/shared/editor_utils.py | 9 +++++---- tests/system/suite_editors/tst_basic_cpp_support/test.py | 5 +---- tests/system/suite_tools/tst_codepasting/test.py | 3 ++- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/tests/system/shared/editor_utils.py b/tests/system/shared/editor_utils.py index 9b391b4497b..25042f95411 100644 --- a/tests/system/shared/editor_utils.py +++ b/tests/system/shared/editor_utils.py @@ -23,6 +23,10 @@ # ############################################################################ +def jumpToFirstLine(editor): + home = "" if platform.system() == 'Darwin' else "" + 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(), "") - else: - type(getEditor(), "") + jumpToFirstLine(getEditor()) found = False if isRegex: regex = re.compile(line) diff --git a/tests/system/suite_editors/tst_basic_cpp_support/test.py b/tests/system/suite_editors/tst_basic_cpp_support/test.py index 77e88228713..69e43adf7fe 100644 --- a/tests/system/suite_editors/tst_basic_cpp_support/test.py +++ b/tests/system/suite_editors/tst_basic_cpp_support/test.py @@ -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, "") - else: - type(cppwindow, "") + jumpToFirstLine(cppwindow) type(cppwindow, "") clickButton(waitForObject(":*Qt Creator_Utils::IconButton")) diff --git a/tests/system/suite_tools/tst_codepasting/test.py b/tests/system/suite_tools/tst_codepasting/test.py index fc2459ae518..5a696753102 100644 --- a/tests/system/suite_tools/tst_codepasting/test.py +++ b/tests/system/suite_tools/tst_codepasting/test.py @@ -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, "") + 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