forked from qt-creator/qt-creator
LineNumberFilter: Use Acceptor for LocatorFilterEntry
Change-Id: Id7da6d01a412633600c3ef905a5ddb18e9587bd7 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -5,19 +5,10 @@
|
|||||||
|
|
||||||
#include "texteditortr.h"
|
#include "texteditortr.h"
|
||||||
|
|
||||||
#include <coreplugin/coreconstants.h>
|
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
#include <coreplugin/icore.h>
|
|
||||||
#include <coreplugin/modemanager.h>
|
|
||||||
|
|
||||||
#include <QMetaType>
|
|
||||||
#include <QPair>
|
|
||||||
#include <QVariant>
|
|
||||||
|
|
||||||
using LineColumn = QPair<int, int>;
|
|
||||||
Q_DECLARE_METATYPE(LineColumn)
|
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
namespace TextEditor::Internal {
|
namespace TextEditor::Internal {
|
||||||
|
|
||||||
@@ -54,9 +45,6 @@ QList<LocatorFilterEntry> LineNumberFilter::matchesFor(QFutureInterface<LocatorF
|
|||||||
if (!ok)
|
if (!ok)
|
||||||
return value;
|
return value;
|
||||||
if (m_hasCurrentEditor && (line > 0 || column > 0)) {
|
if (m_hasCurrentEditor && (line > 0 || column > 0)) {
|
||||||
LineColumn data;
|
|
||||||
data.first = line;
|
|
||||||
data.second = column - 1; // column API is 0-based
|
|
||||||
QString text;
|
QString text;
|
||||||
if (line > 0 && column > 0)
|
if (line > 0 && column > 0)
|
||||||
text = Tr::tr("Line %1, Column %2").arg(line).arg(column);
|
text = Tr::tr("Line %1, Column %2").arg(line).arg(column);
|
||||||
@@ -64,28 +52,20 @@ QList<LocatorFilterEntry> LineNumberFilter::matchesFor(QFutureInterface<LocatorF
|
|||||||
text = Tr::tr("Line %1").arg(line);
|
text = Tr::tr("Line %1").arg(line);
|
||||||
else
|
else
|
||||||
text = Tr::tr("Column %1").arg(column);
|
text = Tr::tr("Column %1").arg(column);
|
||||||
LocatorFilterEntry entry(this, text);
|
LocatorFilterEntry entry;
|
||||||
entry.internalData = QVariant::fromValue(data);
|
entry.displayName = text;
|
||||||
|
entry.acceptor = [line, targetColumn = column - 1] {
|
||||||
|
IEditor *editor = EditorManager::currentEditor();
|
||||||
|
if (!editor)
|
||||||
|
return AcceptResult();
|
||||||
|
EditorManager::addCurrentPositionToNavigationHistory();
|
||||||
|
editor->gotoLine(line < 1 ? editor->currentLine() : line, targetColumn);
|
||||||
|
EditorManager::activateEditor(editor);
|
||||||
|
return AcceptResult();
|
||||||
|
};
|
||||||
value.append(entry);
|
value.append(entry);
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LineNumberFilter::accept(const LocatorFilterEntry &selection,
|
|
||||||
QString *newText, int *selectionStart, int *selectionLength) const
|
|
||||||
{
|
|
||||||
Q_UNUSED(newText)
|
|
||||||
Q_UNUSED(selectionStart)
|
|
||||||
Q_UNUSED(selectionLength)
|
|
||||||
IEditor *editor = EditorManager::currentEditor();
|
|
||||||
if (editor) {
|
|
||||||
EditorManager::addCurrentPositionToNavigationHistory();
|
|
||||||
LineColumn data = selection.internalData.value<LineColumn>();
|
|
||||||
if (data.first < 1) // jump to column in same line
|
|
||||||
data.first = editor->currentLine();
|
|
||||||
editor->gotoLine(data.first, data.second);
|
|
||||||
EditorManager::activateEditor(editor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // TextEditor::Internal
|
} // TextEditor::Internal
|
||||||
|
@@ -5,10 +5,6 @@
|
|||||||
|
|
||||||
#include <coreplugin/locator/ilocatorfilter.h>
|
#include <coreplugin/locator/ilocatorfilter.h>
|
||||||
|
|
||||||
#include <QString>
|
|
||||||
#include <QList>
|
|
||||||
#include <QFutureInterface>
|
|
||||||
|
|
||||||
namespace Core { class IEditor; }
|
namespace Core { class IEditor; }
|
||||||
|
|
||||||
namespace TextEditor {
|
namespace TextEditor {
|
||||||
@@ -24,9 +20,6 @@ public:
|
|||||||
void prepareSearch(const QString &entry) override;
|
void prepareSearch(const QString &entry) override;
|
||||||
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
|
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
|
||||||
const QString &entry) override;
|
const QString &entry) override;
|
||||||
void accept(const Core::LocatorFilterEntry &selection,
|
|
||||||
QString *newText, int *selectionStart, int *selectionLength) const override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_hasCurrentEditor = false;
|
bool m_hasCurrentEditor = false;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user