Commit 1fa3a0e8 authored by Gleb Popov's avatar Gleb Popov 💬

Add ability to get cursor data from URL query arguments, like file://foo.txt?line=123&column=456

Summary: CCBUG: 398998

Test Plan: Opening a file with such URL works in both KWrite and Kate.

Reviewers: #kate

Subscribers: kwrite-devel

Tags: #kate

Differential Revision: https://phabricator.kde.org/D18099
parent 8eda0bb4
......@@ -189,6 +189,21 @@ bool KateApp::startupKate()
if (info.cursor.isValid()) {
setCursor(info.cursor.line(), info.cursor.column());
}
else if (info.url.hasQuery()) {
QUrlQuery q(info.url);
QString lineStr = q.queryItemValue(QStringLiteral("line"));
QString columnStr = q.queryItemValue(QStringLiteral("column"));
int line = lineStr.toInt();
if (line > 0)
line--;
int column = columnStr.toInt();
if (column > 0)
column--;
setCursor(line, column);
}
} else {
KMessageBox::sorry(activeKateMainWindow(),
i18n("The file '%1' could not be opened: it is not a normal file, it is a folder.", info.url.toString()));
......
......@@ -39,6 +39,7 @@
#include <QTextCodec>
#include <QFileInfo>
#include <QDir>
#include <QUrlQuery>
#include "../urlinfo.h"
......@@ -267,6 +268,21 @@ extern "C" Q_DECL_EXPORT int main(int argc, char **argv)
if (info.cursor.isValid()) {
t->view()->setCursorPosition(info.cursor);
}
else if (info.url.hasQuery()) {
QUrlQuery q(info.url);
QString lineStr = q.queryItemValue(QStringLiteral("line"));
QString columnStr = q.queryItemValue(QStringLiteral("column"));
line = lineStr.toInt();
if (line > 0)
line--;
column = columnStr.toInt();
if (column > 0)
column--;
t->view()->setCursorPosition(KTextEditor::Cursor(line, column));
}
} else {
KMessageBox::sorry(nullptr, i18n("The file '%1' could not be opened: it is not a normal file, it is a folder.", info.url.toString()));
}
......
Markdown is supported
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