diff --git a/src/document/katedocument.h b/src/document/katedocument.h --- a/src/document/katedocument.h +++ b/src/document/katedocument.h @@ -1400,11 +1400,11 @@ /** * current autobrace range */ - QSharedPointer m_currentAutobraceRange; + QList> m_currentAutobraceRanges; /** * current autobrace closing character (e.g. ']') */ - QChar m_currentAutobraceClosingChar; + QList m_currentAutobraceClosingChars; private Q_SLOTS: void checkCursorForAutobrace(KTextEditor::View* view, const KTextEditor::Cursor& newPos); diff --git a/src/document/katedocument.cpp b/src/document/katedocument.cpp --- a/src/document/katedocument.cpp +++ b/src/document/katedocument.cpp @@ -3026,9 +3026,10 @@ /** * closing bracket for the autobracket we inserted earlier? */ - if (m_currentAutobraceClosingChar == typedChar && m_currentAutobraceRange) { + if (m_currentAutobraceClosingChars.back() == typedChar && !m_currentAutobraceRanges.empty()) { // do nothing - m_currentAutobraceRange.reset(nullptr); + m_currentAutobraceRanges.pop_back(); + m_currentAutobraceClosingChars.pop_back(); view->cursorRight(); return true; } @@ -3146,15 +3147,16 @@ insertText(view->cursorPosition(), QString(closingBracket)); const auto insertedAt(view->cursorPosition()); view->setCursorPosition(cursorPos); - m_currentAutobraceRange.reset(newMovingRange({cursorPos - Cursor{0, 1}, insertedAt}, - KTextEditor::MovingRange::DoNotExpand)); + QSharedPointer newRange(newMovingRange({cursorPos - Cursor{0, 1}, insertedAt}, + KTextEditor::MovingRange::DoNotExpand)); + m_currentAutobraceRanges.push_back(newRange); connect(view, &View::cursorPositionChanged, this, &DocumentPrivate::checkCursorForAutobrace, Qt::UniqueConnection); // add bracket to chars inserted! needed for correct signals + indent chars.append(closingBracket); } - m_currentAutobraceClosingChar = closingBracket; + m_currentAutobraceClosingChars.push_back(closingBracket); } // end edit session here, to have updated HL in userTypedChar! @@ -3177,8 +3179,9 @@ } void KTextEditor::DocumentPrivate::checkCursorForAutobrace(KTextEditor::View*, const KTextEditor::Cursor& newPos) { - if ( m_currentAutobraceRange && ! m_currentAutobraceRange->toRange().contains(newPos) ) { - m_currentAutobraceRange.clear(); + while ( !m_currentAutobraceRanges.empty() && !m_currentAutobraceRanges.back()->toRange().contains(newPos) ) { + m_currentAutobraceRanges.pop_back(); + m_currentAutobraceClosingChars.pop_back(); } } @@ -3335,12 +3338,11 @@ } } } - if ( m_currentAutobraceRange ) { - const auto r = m_currentAutobraceRange->toRange(); + if ( !m_currentAutobraceRanges.empty() ) { + const auto r = m_currentAutobraceRanges.back()->toRange(); if ( r.columnWidth() == 1 && view->cursorPosition() == r.start() ) { // start parenthesis removed and range length is 1, remove end as well del(view, view->cursorPosition()); - m_currentAutobraceRange.clear(); } } }