Commit e2a3fffd authored by Eric Armbruster's avatar Eric Armbruster Committed by Christoph Cullmann
Browse files

Ensure cursor is valid if only --line is set

We need to make sure the cursor is valid if only the --line or only the --column argument is set.

To achieve this, set the default value for column and line to 0 and explicitly return an invalid cursor when both options are not set.

BUG: 453689
parent e6f6b6fa
Pipeline #177974 passed with stage
in 4 minutes
......@@ -450,42 +450,35 @@ void KateApp::openDocUrlDocumentDestroyed(QObject *document)
KTextEditor::Cursor KateApp::cursorFromArgs()
{
int line = -1;
int column = -1;
bool hasLine = m_args.isSet(QStringLiteral("line"));
bool hasColumn = m_args.isSet(QStringLiteral("column"));
if (m_args.isSet(QStringLiteral("line"))) {
line = m_args.value(QStringLiteral("line")).toInt() - 1;
if (!hasLine && !hasColumn) {
return KTextEditor::Cursor::invalid();
}
if (m_args.isSet(QStringLiteral("column"))) {
column = m_args.value(QStringLiteral("column")).toInt() - 1;
}
int line = qMax(m_args.value(QStringLiteral("line")).toInt() - 1, 0);
int column = qMax(m_args.value(QStringLiteral("column")).toInt() - 1, 0);
return {line, column};
}
KTextEditor::Cursor KateApp::cursorFromQueryString(const QUrl &url)
{
int line = -1;
int column = -1;
if (!url.hasQuery()) {
return {line, column};
return KTextEditor::Cursor::invalid();
}
QUrlQuery urlQuery(url);
QString lineStr = urlQuery.queryItemValue(QStringLiteral("line"));
QString columnStr = urlQuery.queryItemValue(QStringLiteral("column"));
if (!lineStr.isEmpty()) {
line = lineStr.toInt();
line > 0 && line--;
if (lineStr.isEmpty() && columnStr.isEmpty()) {
return KTextEditor::Cursor::invalid();
}
if (!columnStr.isEmpty()) {
column = columnStr.toInt();
column > 0 && column--;
}
int line = qMax(urlQuery.queryItemValue(QStringLiteral("line")).toInt() - 1, 0);
int column = qMax(urlQuery.queryItemValue(QStringLiteral("column")).toInt() - 1, 0);
return {line, column};
}
......
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