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); }