Commit be861391 authored by Waqar Ahmed's avatar Waqar Ahmed Committed by Christoph Cullmann
Browse files

Allow opening results in new doc + use full doc text if no selection

This is a proposal to add the following two features to textfilter:
- Allow opening results in a new document
- If there is no selection, use full document text

This allows you to run grep / rg like tools to filter text in the
document quickly and view the results. One can do a selection to achieve
the same but the major issue with selection is that, it is very slow if
your document is big.
parent 67205f7f
......@@ -57,6 +57,7 @@ PluginKateTextFilter::~PluginKateTextFilter()
QObject *PluginKateTextFilter::createView(KTextEditor::MainWindow *mainWindow)
m_mainWindow = mainWindow;
// create a plugin view
return new PluginViewKateTextFilter(this, mainWindow);
......@@ -93,6 +94,14 @@ void PluginKateTextFilter::slotFilterProcessExited(int, QProcess::ExitStatus)
if (newDocument) {
auto v = m_mainWindow->openUrl(QUrl());
if (v && v->document()) {
if (copyResult) {
......@@ -122,6 +131,8 @@ static void slipInFilter(KProcess &proc, KTextEditor::View &view, const QString
if (view.selection()) {
inputText = view.selectionText();
} else {
inputText = view.document()->text();
......@@ -165,18 +176,22 @@ void PluginKateTextFilter::slotEditFilter()
QStringList items = config.readEntry("Completion list", QStringList());
copyResult = config.readEntry("Copy result", false);
mergeOutput = config.readEntry("Merge output", true);
newDocument = config.readEntry("New Document", false);
ui.filterBox->setHistoryItems(items, true);
if (dialog.exec() == QDialog::Accepted) {
copyResult = ui.copyResult->isChecked();
mergeOutput = ui.mergeOutput->isChecked();
newDocument = ui.newDoc->isChecked();
const QString filter = ui.filterBox->currentText();
if (!filter.isEmpty()) {
config.writeEntry("New Document", newDocument);
config.writeEntry("Completion list", ui.filterBox->historyItems());
config.writeEntry("Copy result", copyResult);
config.writeEntry("Merge output", mergeOutput);
......@@ -49,6 +49,8 @@ private:
QStringList completionList;
bool copyResult = false;
bool mergeOutput = false;
bool newDocument = false;
KTextEditor::MainWindow *m_mainWindow;
public Q_SLOTS:
void slotEditFilter();
void slotFilterReceivedStdout();
......@@ -7,7 +7,7 @@
<property name="windowTitle">
......@@ -31,7 +31,13 @@
<widget class="KHistoryComboBox" name="filterBox">
<widget class="KHistoryComboBox" name="filterBox"/>
<widget class="QCheckBox" name="newDoc">
<property name="text">
<string>Open results in a new document</string>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment