Commit 8eae8726 authored by Lukas Holecek's avatar Lukas Holecek Committed by hjk
Browse files

fakevim: Fix for searches with an empty match

If searching (in "/" command mode) with regular expression "\\b" or
".{0}" the search takes infinitely long.

This fix highlights one character to the right of empty match
(behaviour is similar in Vim).

Change-Id: I5113177cf6af0ef0197e14f0165227e7538a3d1d
Reviewed-by: default avatarhjk <>
parent 42a26ad4
......@@ -3920,11 +3920,6 @@ static QRegExp vimPatternToQtPattern(QString needle, QTextDocument::FindFlags *f
// FIXME: Rough mapping of a common case.
if (needle.startsWith(_("\\<")) && needle.endsWith(_("\\>")))
(*flags) |= QTextDocument::FindWholeWords;
// Half-hearted attempt at removing pitfalls.
if (needle.startsWith(_(".*")))
needle = needle.mid(2);
if (needle.endsWith(_(".*")))
needle = needle.left(needle.size() - 2);
needle.remove(_("\\<")); // start of word
needle.remove(_("\\>")); // end of word
......@@ -4046,6 +4041,8 @@ void FakeVimHandler::Private::highlightMatches(const QString &needle)
tc = tc.document()->find(needleExp, tc.position(), flags);
if (tc.isNull())
if (!tc.hasSelection())
tc.movePosition(Right, KeepAnchor, 1);
QTextEdit::ExtraSelection sel;
sel.cursor = tc;
sel.format = tc.blockCharFormat();
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