diff options
author | hjk <qtc-committer@nokia.com> | 2010-08-16 16:46:32 +0200 |
---|---|---|
committer | hjk <qtc-committer@nokia.com> | 2010-08-16 16:47:01 +0200 |
commit | 362c41be5b1fdd0da8423e769d1cdc0989ba6b41 (patch) | |
tree | 770f2098ea49716033c1594569d8eba46178f993 /src | |
parent | a8747f32e4c8c4c0b800eb9eb026057350a1d4b6 (diff) | |
download | qt-creator-362c41be5b1fdd0da8423e769d1cdc0989ba6b41.tar.gz |
fakevim: slightly better support for regular expressions in search patterns
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/fakevim/fakevimhandler.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/plugins/fakevim/fakevimhandler.cpp b/src/plugins/fakevim/fakevimhandler.cpp index 5fe2e6171f..d31da4521d 100644 --- a/src/plugins/fakevim/fakevimhandler.cpp +++ b/src/plugins/fakevim/fakevimhandler.cpp @@ -3569,9 +3569,14 @@ bool FakeVimHandler::Private::handleExPluginCommand(const ExCommand &cmd) static void vimPatternToQtPattern(QString *needle, QTextDocument::FindFlags *flags) { - // FIXME: Rough mapping of a common case + // 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 //qDebug() << "NEEDLE " << needle0 << needle; @@ -3631,10 +3636,11 @@ void FakeVimHandler::Private::search(const SearchData &sd) sd.forward ? ++startPos : --startPos; m_searchCursor = QTextCursor(); - QTextCursor tc = m_tc.document()->find(needle, startPos, flags); + QRegExp needleExp(needle); + QTextCursor tc = m_tc.document()->find(needleExp, startPos, flags); if (tc.isNull()) { int startPos = sd.forward ? 0 : lastPositionInDocument(); - tc = m_tc.document()->find(needle, startPos, flags); + tc = m_tc.document()->find(needleExp, startPos, flags); if (tc.isNull()) { if (!incSearch) { highlightMatches(QString()); @@ -3652,6 +3658,7 @@ void FakeVimHandler::Private::search(const SearchData &sd) } // Set Cursor. + const int size = tc.position() - tc.anchor(); tc.setPosition(qMin(tc.position(), tc.anchor()), MoveAnchor); tc.clearSelection(); m_tc = tc; @@ -3664,7 +3671,7 @@ void FakeVimHandler::Private::search(const SearchData &sd) if (incSearch && sd.highlightCursor) { m_searchCursor = m_tc; m_searchCursor.setPosition(m_tc.position(), MoveAnchor); - m_searchCursor.setPosition(m_tc.position() + needle.size(), KeepAnchor); + m_searchCursor.setPosition(m_tc.position() + size, KeepAnchor); } setTargetColumn(); @@ -3689,8 +3696,9 @@ void FakeVimHandler::Private::highlightMatches(const QString &needle0) QTextDocument::FindFlags flags = QTextDocument::FindCaseSensitively; QString needle = needle0; vimPatternToQtPattern(&needle, &flags); + QRegExp needleExp(needle); while (1) { - tc = tc.document()->find(needle, tc.position(), flags); + tc = tc.document()->find(needleExp, tc.position(), flags); if (tc.isNull()) break; QTextEdit::ExtraSelection sel; |