diff options
author | d3fault <d3fault@d3fault.net> | 2015-03-05 17:43:11 -0700 |
---|---|---|
committer | hjk <hjk@theqtcompany.com> | 2015-03-06 08:05:42 +0000 |
commit | 44e7eca55942589e1cc3da4790bc2e38550f2791 (patch) | |
tree | 4955fed28ebfa5dcf175d281b0281890a044b12b /src/plugins/coreplugin/editormanager | |
parent | 2fb9c3c7abc93a9237e72972ee222b2a2628007e (diff) | |
download | qt-creator-44e7eca55942589e1cc3da4790bc2e38550f2791.tar.gz |
Add goto column number command line arg to complement goto line number
When specifying a filename as an argument, you can append a colon (or a
plus) followed by a number to indicate which line the cursor should be
positioned at in that file. This patch adds the same functionality but
for the column position as well. Ex: main.cpp:5:4 would open main.cpp
and put the cursor at line 5 column 4. The column number is optional,
just like the line number before it. It should be noted that specified
column numbers larger than the amount of characters available on that
line are wrapped onto subsequent lines.
Change-Id: I50208500fa43e43a9514d2be21630b3c607119a6
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
Reviewed-by: hjk <hjk@theqtcompany.com>
Diffstat (limited to 'src/plugins/coreplugin/editormanager')
-rw-r--r-- | src/plugins/coreplugin/editormanager/editormanager.cpp | 31 | ||||
-rw-r--r-- | src/plugins/coreplugin/editormanager/editormanager.h | 2 |
2 files changed, 25 insertions, 8 deletions
diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index 82a156ab42..93ce68805b 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -173,7 +173,7 @@ void EditorManagerPlaceHolder::currentModeChanged(IMode *mode) static EditorManager *m_instance = 0; static EditorManagerPrivate *d; -static int extractLineNumber(QString *fileName) +static int extractNumericSuffix(QString *fileName) { int i = fileName->length() - 1; for (; i >= 0; --i) { @@ -195,6 +195,22 @@ static int extractLineNumber(QString *fileName) return -1; } +static void extractLineAndColumnNumbers(QString *fileName, int *lineNumber, int *columnNumber) +{ + *lineNumber = -1; + *columnNumber = -1; + int lastSuffix = extractNumericSuffix(fileName); + if (lastSuffix == -1) + return; + int secondToLastSuffix = extractNumericSuffix(fileName); + if (secondToLastSuffix == -1) { + *lineNumber = lastSuffix; + return; + } + *lineNumber = secondToLastSuffix; + *columnNumber = lastSuffix - 1; //column is 0 based, despite line being 1 based +} + static QString autoSaveName(const QString &fileName) { return fileName + QLatin1String(".autosave"); @@ -533,8 +549,9 @@ IEditor *EditorManagerPrivate::openEditor(EditorView *view, const QString &fileN QString fn = fileName; QFileInfo fi(fn); int lineNumber = -1; - if ((flags & EditorManager::CanContainLineNumber) && !fi.exists()) { - lineNumber = extractLineNumber(&fn); + int columnNumber = -1; + if ((flags & EditorManager::CanContainLineAndColumnNumber) && !fi.exists()) { + extractLineAndColumnNumbers(&fn, &lineNumber, &columnNumber); if (lineNumber != -1) fi.setFile(fn); } @@ -549,8 +566,8 @@ IEditor *EditorManagerPrivate::openEditor(EditorView *view, const QString &fileN if (!editors.isEmpty()) { IEditor *editor = editors.first(); editor = activateEditor(view, editor, flags); - if (editor && flags & EditorManager::CanContainLineNumber) - editor->gotoLine(lineNumber, -1); + if (editor && flags & EditorManager::CanContainLineAndColumnNumber) + editor->gotoLine(lineNumber, columnNumber); return editor; } @@ -586,8 +603,8 @@ IEditor *EditorManagerPrivate::openEditor(EditorView *view, const QString &fileN if (editor == result) restoreEditorState(editor); - if (flags & EditorManager::CanContainLineNumber) - editor->gotoLine(lineNumber, -1); + if (flags & EditorManager::CanContainLineAndColumnNumber) + editor->gotoLine(lineNumber, columnNumber); QApplication::restoreOverrideCursor(); return result; diff --git a/src/plugins/coreplugin/editormanager/editormanager.h b/src/plugins/coreplugin/editormanager/editormanager.h index dc94580250..6d0f208f44 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.h +++ b/src/plugins/coreplugin/editormanager/editormanager.h @@ -102,7 +102,7 @@ public: DoNotChangeCurrentEditor = 1, IgnoreNavigationHistory = 2, DoNotMakeVisible = 4, - CanContainLineNumber = 8, + CanContainLineAndColumnNumber = 8, OpenInOtherSplit = 16, DoNotSwitchToDesignMode = 32 }; |