From 5ce704b394b71f72df1c16d57b1ef2382bbc1d11 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Thu, 27 May 2021 10:10:31 +0200 Subject: [PATCH] Core: Fix opening files with line column postfix Having two files with in a locator filter with the same name except one having an addition line column postfix like /tmp/asd /tmp/asd+12 made it impossible to open the second file from the locator. Since we already have the selected file and the locator filter string we also can use that to parse the postfix manually and make sure to always open the selected file from the locator widget. Change-Id: I389603622fbdef01d09b3584192ed6d47e9e170f Reviewed-by: Christian Stenger --- .../coreplugin/locator/basefilefilter.cpp | 21 +++++++++++++++++-- .../coreplugin/locator/basefilefilter.h | 1 + .../coreplugin/locator/filesystemfilter.cpp | 7 ++----- .../locator/opendocumentsfilter.cpp | 5 +++-- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/plugins/coreplugin/locator/basefilefilter.cpp b/src/plugins/coreplugin/locator/basefilefilter.cpp index ea6e82c7fed..d75424b69aa 100644 --- a/src/plugins/coreplugin/locator/basefilefilter.cpp +++ b/src/plugins/coreplugin/locator/basefilefilter.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -224,8 +225,24 @@ void BaseFileFilter::accept(LocatorFilterEntry selection, Q_UNUSED(newText) Q_UNUSED(selectionStart) Q_UNUSED(selectionLength) - EditorManager::openEditor(selection.internalData.toString(), Id(), - EditorManager::CanContainLineAndColumnNumber); + openEditorAt(selection); +} + +void BaseFileFilter::openEditorAt(const LocatorFilterEntry& selection) +{ + const FilePath selectedPath = FilePath::fromString(selection.fileName); + const FilePath locatorText = FilePath::fromVariant(selection.internalData); + const int postfixLength = locatorText.fileName().length() - selectedPath.fileName().length(); + if (postfixLength > 0) { + const QString postfix = selection.internalData.toString().right(postfixLength); + int postfixPos = -1; + const LineColumn lineColumn = LineColumn::extractFromFileName(postfix, postfixPos); + if (postfixPos >= 0) { + EditorManager::openEditorAt(Link(selectedPath, lineColumn.line, lineColumn.column)); + return; + } + } + EditorManager::openEditor(selectedPath); } /*! diff --git a/src/plugins/coreplugin/locator/basefilefilter.h b/src/plugins/coreplugin/locator/basefilefilter.h index 3757a2b77de..84eaa2208a0 100644 --- a/src/plugins/coreplugin/locator/basefilefilter.h +++ b/src/plugins/coreplugin/locator/basefilefilter.h @@ -70,6 +70,7 @@ public: const QString &entry) override; void accept(LocatorFilterEntry selection, QString *newText, int *selectionStart, int *selectionLength) const override; + static void openEditorAt(const LocatorFilterEntry &selection); protected: void setFileIterator(Iterator *iterator); diff --git a/src/plugins/coreplugin/locator/filesystemfilter.cpp b/src/plugins/coreplugin/locator/filesystemfilter.cpp index 47c9be47c60..76d41029342 100644 --- a/src/plugins/coreplugin/locator/filesystemfilter.cpp +++ b/src/plugins/coreplugin/locator/filesystemfilter.cpp @@ -25,6 +25,7 @@ #include "filesystemfilter.h" +#include "basefilefilter.h" #include "locatorwidget.h" #include @@ -207,11 +208,7 @@ void FileSystemFilter::accept(LocatorFilterEntry selection, file.close(); VcsManager::promptToAdd(QFileInfo(targetFile).absolutePath(), { targetFile }); } - const QFileInfo fileInfo(targetFile); - const QString cleanedFilePath = QDir::cleanPath(fileInfo.absoluteFilePath()); - EditorManager::openEditor(cleanedFilePath, - Id(), - EditorManager::CanContainLineAndColumnNumber); + BaseFileFilter::openEditorAt(selection); }, Qt::QueuedConnection); } } diff --git a/src/plugins/coreplugin/locator/opendocumentsfilter.cpp b/src/plugins/coreplugin/locator/opendocumentsfilter.cpp index 6a74cc8d7a4..bdd1ca78a6f 100644 --- a/src/plugins/coreplugin/locator/opendocumentsfilter.cpp +++ b/src/plugins/coreplugin/locator/opendocumentsfilter.cpp @@ -27,8 +27,10 @@ #include #include +#include #include #include +#include #include #include @@ -124,6 +126,5 @@ void OpenDocumentsFilter::accept(LocatorFilterEntry selection, Q_UNUSED(newText) Q_UNUSED(selectionStart) Q_UNUSED(selectionLength) - EditorManager::openEditor(selection.internalData.toString(), Id(), - EditorManager::CanContainLineAndColumnNumber); + BaseFileFilter::openEditorAt(selection); }