diff --git a/src/plugins/fakevim/fakevimhandler.cpp b/src/plugins/fakevim/fakevimhandler.cpp index 57f212ea7e78eda4c95d29b2380dd96fcf9c25de..6c179cf902b33b57cd10dbc42dc9674c87f393fc 100644 --- a/src/plugins/fakevim/fakevimhandler.cpp +++ b/src/plugins/fakevim/fakevimhandler.cpp @@ -1846,6 +1846,16 @@ void FakeVimHandler::Private::moveToNextWord(bool simple) void FakeVimHandler::Private::moveToMatchingParanthesis() { + bool moved = false; + bool forward = false; + + emit q->moveToMatchingParenthesis(&moved, &forward, &m_tc); + + if (moved && forward) { + if (m_submode == NoSubMode || m_submode == ZSubMode || m_submode == RegisterSubMode) + m_tc.movePosition(Left, KeepAnchor, 1); + } + #if 0 // FIXME: remove TextEditor dependency bool undoFakeEOL = false; diff --git a/src/plugins/fakevim/fakevimhandler.h b/src/plugins/fakevim/fakevimhandler.h index a083f346dd4d25ddd629c5c26b01b7aeab8287fe..c308c3cb94e05c5d313655b902a27a7fd7936439 100644 --- a/src/plugins/fakevim/fakevimhandler.h +++ b/src/plugins/fakevim/fakevimhandler.h @@ -79,6 +79,7 @@ signals: void selectionChanged(const QList<QTextEdit::ExtraSelection> &selection); void writeFileRequested(bool *handled, const QString &fileName, const QString &contents); + void moveToMatchingParenthesis(bool *moved, bool *forward, QTextCursor *cursor); private: bool eventFilter(QObject *ob, QEvent *ev); diff --git a/src/plugins/fakevim/fakevimplugin.cpp b/src/plugins/fakevim/fakevimplugin.cpp index 50d45ff8769f1731c67317ca938dca7be727a9fd..c8b2898d88e392c8fb556001f78e98050c8b2c1d 100644 --- a/src/plugins/fakevim/fakevimplugin.cpp +++ b/src/plugins/fakevim/fakevimplugin.cpp @@ -122,6 +122,7 @@ private slots: void showExtraInformation(const QString &msg); void changeSelection(const QList<QTextEdit::ExtraSelection> &selections); void writeFile(bool *handled, const QString &fileName, const QString &contents); + void moveToMatchingParenthesis(bool *moved, bool *forward, QTextCursor *cursor); private: FakeVimPlugin *q; @@ -203,6 +204,8 @@ void FakeVimPluginPrivate::installHandler(Core::IEditor *editor) this, SLOT(writeFile(bool*,QString,QString))); connect(handler, SIGNAL(selectionChanged(QList<QTextEdit::ExtraSelection>)), this, SLOT(changeSelection(QList<QTextEdit::ExtraSelection>))); + connect(handler, SIGNAL(moveToMatchingParenthesis(bool*,bool*,QTextCursor*)), + this, SLOT(moveToMatchingParenthesis(bool*,bool*,QTextCursor*))); handler->setupWidget(); handler->setExtraData(editor); @@ -250,6 +253,42 @@ void FakeVimPluginPrivate::writeFile(bool *handled, } } +void FakeVimPluginPrivate::moveToMatchingParenthesis(bool *moved, bool *forward, + QTextCursor *cursor) +{ + *moved = false; + + bool undoFakeEOL = false; + if (cursor->atBlockEnd() && cursor->block().length() > 1) { + cursor->movePosition(QTextCursor::Left, QTextCursor::KeepAnchor, 1); + undoFakeEOL = true; + } + TextEditor::TextBlockUserData::MatchType match + = TextEditor::TextBlockUserData::matchCursorForward(cursor); + if (match == TextEditor::TextBlockUserData::Match) { + *moved = true; + *forward = true; + } else { + if (undoFakeEOL) + cursor->movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 1); + if (match == TextEditor::TextBlockUserData::NoMatch) { + // backward matching is according to the character before the cursor + bool undoMove = false; + if (!cursor->atBlockEnd()) { + cursor->movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 1); + undoMove = true; + } + match = TextEditor::TextBlockUserData::matchCursorBackward(cursor); + if (match == TextEditor::TextBlockUserData::Match) { + *moved = true; + *forward = false; + } else if (undoMove) { + cursor->movePosition(QTextCursor::Left, QTextCursor::KeepAnchor, 1); + } + } + } +} + void FakeVimPluginPrivate::removeHandler() { if (FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender())) {