Commit cab17fbe authored by Waqar Ahmed's avatar Waqar Ahmed
Browse files

Fix snippets not showing up in completion

If you have some text on a line:
	func()
and the cursor is in between the parenthesis and you try to invoke a
snippet, kate fails to do so because of what the completionRange
method was doing i.e., trying to select the full line range which imo
sounds not very smart.

It also leads to incorrect text replacement after execution of a snippet
as the range could be anything.

To test, create a snippet "qst" that completes to QStringLiteral("").
Then place your cursor in func() and type qst. Nothing shows up. Add
spaces between parenthesis, snippet will now show up but when you
execute it, it results in `tringLiteral("")`.

(cherry picked from commit b0b5da9c)
parent 18037e7b
......@@ -136,28 +136,6 @@ int SnippetCompletionModel::rowCount(const QModelIndex &parent) const
return m_snippets.count(); // only the children
}
}
KTextEditor::Range SnippetCompletionModel::completionRange(KTextEditor::View *view, const KTextEditor::Cursor &position)
{
const QString &line = view->document()->line(position.line());
KTextEditor::Range range(position, position);
// include everything non-space before
for (int i = position.column() - 1; i >= 0; --i) {
if (line.at(i).isSpace()) {
break;
} else {
range.setStart(KTextEditor::Cursor(range.start().line(), i));
}
}
// include everything non-space after
for (int i = position.column() + 1; i < line.length(); ++i) {
if (line.at(i).isSpace()) {
break;
} else {
range.setEnd(KTextEditor::Cursor(range.end().line(), i));
}
}
return range;
}
bool SnippetCompletionModel::shouldAbortCompletion(KTextEditor::View *view, const KTextEditor::Range &range, const QString &currentCompletion)
{
......
......@@ -38,7 +38,6 @@ public:
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex &index) const override;
KTextEditor::Range completionRange(KTextEditor::View *view, const KTextEditor::Cursor &position) override;
bool shouldAbortCompletion(KTextEditor::View *view, const KTextEditor::Range &range, const QString &currentCompletion) override;
private:
......
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