Commit 554f4fe6 authored by mae's avatar mae
Browse files

ensure visibility for extra blocks that are auto inserted

parent 061865ef
......@@ -1356,13 +1356,13 @@ bool CPPEditor::autoBackspace(QTextCursor &cursor)
return false;
}
void CPPEditor::paragraphSeparatorAboutToBeInserted(QTextCursor &cursor)
int CPPEditor::paragraphSeparatorAboutToBeInserted(QTextCursor &cursor)
{
if (characterAt(cursor.position()-1) != QLatin1Char('{'))
return;
return 0;
if (!contextAllowsAutoParentheses(cursor))
return;
return 0;
// verify that we indeed do have an extra opening brace in the document
......@@ -1387,7 +1387,9 @@ void CPPEditor::paragraphSeparatorAboutToBeInserted(QTextCursor &cursor)
}
cursor.setPosition(pos);
m_allowSkippingOfBlockEnd = true;
return 1;
}
return 0;
}
bool CPPEditor::contextAllowsAutoParentheses(const QTextCursor &cursor) const
......
......@@ -215,7 +215,7 @@ protected:
bool isElectricCharacter(const QChar &ch) const;
QString autoComplete(QTextCursor &cursor, const QString &text) const;
bool autoBackspace(QTextCursor &cursor);
void paragraphSeparatorAboutToBeInserted(QTextCursor &cursor);
int paragraphSeparatorAboutToBeInserted(QTextCursor &cursor);
bool contextAllowsAutoParentheses(const QTextCursor &cursor) const;
......
......@@ -890,7 +890,7 @@ void BaseTextEditor::keyPressEvent(QKeyEvent *e)
const TabSettings &ts = d->m_document->tabSettings();
cursor.beginEditBlock();
paragraphSeparatorAboutToBeInserted(cursor); // virtual
int extraBlocks = paragraphSeparatorAboutToBeInserted(cursor); // virtual
if (ts.m_autoIndent) {
cursor.insertBlock();
......@@ -902,6 +902,16 @@ void BaseTextEditor::keyPressEvent(QKeyEvent *e)
}
cursor.endEditBlock();
e->accept();
if (extraBlocks > 0) {
QTextCursor ensureVisible = cursor;
while (extraBlocks > 0) {
--extraBlocks;
ensureVisible.movePosition(QTextCursor::NextBlock);
}
setTextCursor(ensureVisible);
}
setTextCursor(cursor);
return;
} else if (!ro
......@@ -3279,9 +3289,10 @@ bool BaseTextEditor::autoBackspace(QTextCursor &cursor)
return false;
}
void BaseTextEditor::paragraphSeparatorAboutToBeInserted(QTextCursor &cursor)
int BaseTextEditor::paragraphSeparatorAboutToBeInserted(QTextCursor &cursor)
{
Q_UNUSED(cursor)
Q_UNUSED(cursor);
return 0;
}
void BaseTextEditor::indentBlock(QTextDocument *, QTextBlock, QChar)
......
......@@ -509,8 +509,8 @@ protected:
virtual QString autoComplete(QTextCursor &cursor, const QString &text) const;
// Handles backspace. When returning true, backspace processing is stopped
virtual bool autoBackspace(QTextCursor &cursor);
// Hook to insert special characters on enter
virtual void paragraphSeparatorAboutToBeInserted(QTextCursor &cursor);
// Hook to insert special characters on enter. Returns the number of extra blocks inserted.
virtual int paragraphSeparatorAboutToBeInserted(QTextCursor &cursor);
// Indent a text block based on previous line. Default does nothing
virtual void indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar);
// Indent at cursor. Calls indentBlock for selection or current line.
......
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