aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJarek Kobus <jaroslaw.kobus@qt.io>2023-04-11 22:56:33 +0200
committerJarek Kobus <jaroslaw.kobus@qt.io>2023-04-19 08:52:53 +0000
commitee140a8231e58455727afaeb44f36f00c186edcb (patch)
tree2a0594d894c93cfbae4c02218e2a57ef606df324
parent39b8bdab1788284c96efbf35bfadc07a1d76d85a (diff)
LineNumberFilter: Use Acceptor for LocatorFilterEntry
Change-Id: Id7da6d01a412633600c3ef905a5ddb18e9587bd7 Reviewed-by: Eike Ziller <eike.ziller@qt.io>
-rw-r--r--src/plugins/texteditor/linenumberfilter.cpp44
-rw-r--r--src/plugins/texteditor/linenumberfilter.h7
2 files changed, 12 insertions, 39 deletions
diff --git a/src/plugins/texteditor/linenumberfilter.cpp b/src/plugins/texteditor/linenumberfilter.cpp
index 83f0adaf92..b22c73bfd8 100644
--- a/src/plugins/texteditor/linenumberfilter.cpp
+++ b/src/plugins/texteditor/linenumberfilter.cpp
@@ -5,19 +5,10 @@
#include "texteditortr.h"
-#include <coreplugin/coreconstants.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 Utils;
namespace TextEditor::Internal {
@@ -54,9 +45,6 @@ QList<LocatorFilterEntry> LineNumberFilter::matchesFor(QFutureInterface<LocatorF
if (!ok)
return value;
if (m_hasCurrentEditor && (line > 0 || column > 0)) {
- LineColumn data;
- data.first = line;
- data.second = column - 1; // column API is 0-based
QString text;
if (line > 0 && column > 0)
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);
else
text = Tr::tr("Column %1").arg(column);
- LocatorFilterEntry entry(this, text);
- entry.internalData = QVariant::fromValue(data);
+ LocatorFilterEntry entry;
+ 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);
}
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
diff --git a/src/plugins/texteditor/linenumberfilter.h b/src/plugins/texteditor/linenumberfilter.h
index 03b52f270b..70d2c1b6f0 100644
--- a/src/plugins/texteditor/linenumberfilter.h
+++ b/src/plugins/texteditor/linenumberfilter.h
@@ -5,10 +5,6 @@
#include <coreplugin/locator/ilocatorfilter.h>
-#include <QString>
-#include <QList>
-#include <QFutureInterface>
-
namespace Core { class IEditor; }
namespace TextEditor {
@@ -24,9 +20,6 @@ public:
void prepareSearch(const QString &entry) override;
QList<Core::LocatorFilterEntry> matchesFor(QFutureInterface<Core::LocatorFilterEntry> &future,
const QString &entry) override;
- void accept(const Core::LocatorFilterEntry &selection,
- QString *newText, int *selectionStart, int *selectionLength) const override;
-
private:
bool m_hasCurrentEditor = false;
};