tune auto-parentheses

do not close braces automatically on enter if the next line's indentation
is deeper than the current line's
This commit is contained in:
mae
2009-09-30 17:09:46 +02:00
parent 8356d3360b
commit dadefeaf97

View File

@@ -1537,28 +1537,43 @@ int CPPEditor::paragraphSeparatorAboutToBeInserted(QTextCursor &cursor)
else else
braceDepth= 0; braceDepth= 0;
if (braceDepth > 0) { // we do have an extra brace, let's close it if (braceDepth <= 0)
int pos = cursor.position(); return 0; // braces are all balanced or worse, no need to do anything
MatchingText matchingText; // we have an extra brace , let's see if we should close it
const QString textToInsert = matchingText.insertParagraphSeparator(cursor);
cursor.insertText(textToInsert);
cursor.setPosition(pos); /* verify that the next block is not further intended compared to the current block.
const TabSettings &ts = tabSettings(); This covers the following case:
if (ts.m_autoIndent) {
cursor.insertBlock(); if (condition) {|
indent(document(), cursor, QChar::Null); statement;
} else { */
QString previousBlockText = cursor.block().text(); const TabSettings &ts = tabSettings();
cursor.insertBlock(); QTextBlock block = cursor.block();
cursor.insertText(ts.indentationString(previousBlockText)); int indentation = ts.indentationColumn(block.text());
} if (block.next().isValid()
cursor.setPosition(pos); && ts.indentationColumn(block.next().text()) > indentation)
m_allowSkippingOfBlockEnd = true; return 0;
return 1;
int pos = cursor.position();
MatchingText matchingText;
const QString textToInsert = matchingText.insertParagraphSeparator(cursor);
cursor.insertText(textToInsert);
cursor.setPosition(pos);
if (ts.m_autoIndent) {
cursor.insertBlock();
indent(document(), cursor, QChar::Null);
} else {
QString previousBlockText = cursor.block().text();
cursor.insertBlock();
cursor.insertText(ts.indentationString(previousBlockText));
} }
return 0; cursor.setPosition(pos);
m_allowSkippingOfBlockEnd = true;
return 1;
} }
bool CPPEditor::contextAllowsAutoParentheses(const QTextCursor &cursor, bool CPPEditor::contextAllowsAutoParentheses(const QTextCursor &cursor,