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