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 <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2021-05-27 10:10:31 +02:00
parent 5dedd1fba7
commit 5ce704b394
4 changed files with 25 additions and 9 deletions

View File

@@ -28,6 +28,7 @@
#include <coreplugin/editormanager/editormanager.h>
#include <utils/algorithm.h>
#include <utils/fileutils.h>
#include <utils/linecolumn.h>
#include <utils/link.h>
#include <utils/qtcassert.h>
@@ -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);
}
/*!

View File

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

View File

@@ -25,6 +25,7 @@
#include "filesystemfilter.h"
#include "basefilefilter.h"
#include "locatorwidget.h"
#include <coreplugin/coreconstants.h>
@@ -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);
}
}

View File

@@ -27,8 +27,10 @@
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/editormanager/ieditor.h>
#include <coreplugin/locator/basefilefilter.h>
#include <utils/fileutils.h>
#include <utils/link.h>
#include <utils/linecolumn.h>
#include <QAbstractItemModel>
#include <QFileInfo>
@@ -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);
}