forked from qt-creator/qt-creator
TextEditor: update matching parenthesis in the editor
... after updating the parenthesis in the layout Task-number: QTCREATORBUG-26183 Change-Id: I346046fbc3932b94227c1ac5bee6b0d7c44651e1 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -387,12 +387,12 @@ TextDocumentLayout::~TextDocumentLayout()
|
|||||||
|
|
||||||
void TextDocumentLayout::setParentheses(const QTextBlock &block, const Parentheses &parentheses)
|
void TextDocumentLayout::setParentheses(const QTextBlock &block, const Parentheses &parentheses)
|
||||||
{
|
{
|
||||||
if (parentheses.isEmpty()) {
|
if (TextDocumentLayout::parentheses(block) == parentheses)
|
||||||
if (TextBlockUserData *userData = textUserData(block))
|
return;
|
||||||
userData->clearParentheses();
|
|
||||||
} else {
|
|
||||||
userData(block)->setParentheses(parentheses);
|
userData(block)->setParentheses(parentheses);
|
||||||
}
|
if (auto layout = qobject_cast<TextDocumentLayout *>(block.document()->documentLayout()))
|
||||||
|
emit layout->parenthesesChanged(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
Parentheses TextDocumentLayout::parentheses(const QTextBlock &block)
|
Parentheses TextDocumentLayout::parentheses(const QTextBlock &block)
|
||||||
@@ -684,4 +684,18 @@ void TextDocumentLayout::FoldValidator::finalize()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QDebug operator<<(QDebug debug, const Parenthesis &parenthesis)
|
||||||
|
{
|
||||||
|
QDebugStateSaver saver(debug);
|
||||||
|
debug << (parenthesis.type == Parenthesis::Opened ? "Opening " : "Closing ") << parenthesis.chr
|
||||||
|
<< " at " << parenthesis.pos;
|
||||||
|
|
||||||
|
return debug;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Parenthesis::operator==(const Parenthesis &other) const
|
||||||
|
{
|
||||||
|
return pos == other.pos && chr == other.chr && source == other.source && type == other.type;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace TextEditor
|
} // namespace TextEditor
|
||||||
|
@@ -52,8 +52,12 @@ struct TEXTEDITOR_EXPORT Parenthesis
|
|||||||
QChar chr;
|
QChar chr;
|
||||||
Utils::Id source;
|
Utils::Id source;
|
||||||
Type type = Opened;
|
Type type = Opened;
|
||||||
|
|
||||||
|
bool operator==(const Parenthesis &other) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TEXTEDITOR_EXPORT QDebug operator<<(QDebug debug, const Parenthesis &parenthesis);
|
||||||
|
|
||||||
class TEXTEDITOR_EXPORT CodeFormatterData
|
class TEXTEDITOR_EXPORT CodeFormatterData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -231,6 +235,7 @@ public:
|
|||||||
signals:
|
signals:
|
||||||
void updateExtraArea();
|
void updateExtraArea();
|
||||||
void foldChanged(const int blockNumber, bool folded);
|
void foldChanged(const int blockNumber, bool folded);
|
||||||
|
void parenthesesChanged(const QTextBlock block);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace TextEditor
|
} // namespace TextEditor
|
||||||
|
@@ -1058,6 +1058,7 @@ void TextEditorWidgetPrivate::ctor(const QSharedPointer<TextDocument> &doc)
|
|||||||
// parentheses matcher
|
// parentheses matcher
|
||||||
m_formatRange = true;
|
m_formatRange = true;
|
||||||
m_parenthesesMatchingTimer.setSingleShot(true);
|
m_parenthesesMatchingTimer.setSingleShot(true);
|
||||||
|
m_parenthesesMatchingTimer.setInterval(50);
|
||||||
QObject::connect(&m_parenthesesMatchingTimer, &QTimer::timeout,
|
QObject::connect(&m_parenthesesMatchingTimer, &QTimer::timeout,
|
||||||
this, &TextEditorWidgetPrivate::_q_matchParentheses);
|
this, &TextEditorWidgetPrivate::_q_matchParentheses);
|
||||||
|
|
||||||
@@ -2714,7 +2715,7 @@ void TextEditorWidget::keyPressEvent(QKeyEvent *e)
|
|||||||
|
|
||||||
skip_event:
|
skip_event:
|
||||||
if (!ro && e->key() == Qt::Key_Delete && d->m_parenthesesMatchingEnabled)
|
if (!ro && e->key() == Qt::Key_Delete && d->m_parenthesesMatchingEnabled)
|
||||||
d->m_parenthesesMatchingTimer.start(50);
|
d->m_parenthesesMatchingTimer.start();
|
||||||
|
|
||||||
if (!ro && d->m_contentsChanged && isPrintableText(eventText) && !inOverwriteMode)
|
if (!ro && d->m_contentsChanged && isPrintableText(eventText) && !inOverwriteMode)
|
||||||
d->m_codeAssistant.process();
|
d->m_codeAssistant.process();
|
||||||
@@ -3428,6 +3429,9 @@ void TextEditorWidgetPrivate::setupDocumentSignals()
|
|||||||
QObject::connect(documentLayout, &TextDocumentLayout::updateExtraArea,
|
QObject::connect(documentLayout, &TextDocumentLayout::updateExtraArea,
|
||||||
this, &TextEditorWidgetPrivate::scheduleUpdateHighlightScrollBar);
|
this, &TextEditorWidgetPrivate::scheduleUpdateHighlightScrollBar);
|
||||||
|
|
||||||
|
QObject::connect(documentLayout, &TextDocumentLayout::parenthesesChanged,
|
||||||
|
&m_parenthesesMatchingTimer, QOverload<>::of(&QTimer::start));
|
||||||
|
|
||||||
QObject::connect(documentLayout, &QAbstractTextDocumentLayout::documentSizeChanged,
|
QObject::connect(documentLayout, &QAbstractTextDocumentLayout::documentSizeChanged,
|
||||||
this, &TextEditorWidgetPrivate::scheduleUpdateHighlightScrollBar);
|
this, &TextEditorWidgetPrivate::scheduleUpdateHighlightScrollBar);
|
||||||
|
|
||||||
@@ -5431,7 +5435,7 @@ void TextEditorWidgetPrivate::updateHighlights()
|
|||||||
// Delay update when no matching is displayed yet, to avoid flicker
|
// Delay update when no matching is displayed yet, to avoid flicker
|
||||||
if (q->extraSelections(TextEditorWidget::ParenthesesMatchingSelection).isEmpty()
|
if (q->extraSelections(TextEditorWidget::ParenthesesMatchingSelection).isEmpty()
|
||||||
&& m_bracketsAnimator == nullptr) {
|
&& m_bracketsAnimator == nullptr) {
|
||||||
m_parenthesesMatchingTimer.start(50);
|
m_parenthesesMatchingTimer.start();
|
||||||
} else {
|
} else {
|
||||||
// when we uncheck "highlight matching parentheses"
|
// when we uncheck "highlight matching parentheses"
|
||||||
// we need clear current selection before viewport update
|
// we need clear current selection before viewport update
|
||||||
|
Reference in New Issue
Block a user