forked from qt-creator/qt-creator
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:
@@ -1537,7 +1537,25 @@ 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)
|
||||||
|
return 0; // braces are all balanced or worse, no need to do anything
|
||||||
|
|
||||||
|
// we have an extra brace , let's see if we should close it
|
||||||
|
|
||||||
|
|
||||||
|
/* verify that the next block is not further intended compared to the current block.
|
||||||
|
This covers the following case:
|
||||||
|
|
||||||
|
if (condition) {|
|
||||||
|
statement;
|
||||||
|
*/
|
||||||
|
const TabSettings &ts = tabSettings();
|
||||||
|
QTextBlock block = cursor.block();
|
||||||
|
int indentation = ts.indentationColumn(block.text());
|
||||||
|
if (block.next().isValid()
|
||||||
|
&& ts.indentationColumn(block.next().text()) > indentation)
|
||||||
|
return 0;
|
||||||
|
|
||||||
int pos = cursor.position();
|
int pos = cursor.position();
|
||||||
|
|
||||||
MatchingText matchingText;
|
MatchingText matchingText;
|
||||||
@@ -1545,7 +1563,6 @@ int CPPEditor::paragraphSeparatorAboutToBeInserted(QTextCursor &cursor)
|
|||||||
|
|
||||||
cursor.insertText(textToInsert);
|
cursor.insertText(textToInsert);
|
||||||
cursor.setPosition(pos);
|
cursor.setPosition(pos);
|
||||||
const TabSettings &ts = tabSettings();
|
|
||||||
if (ts.m_autoIndent) {
|
if (ts.m_autoIndent) {
|
||||||
cursor.insertBlock();
|
cursor.insertBlock();
|
||||||
indent(document(), cursor, QChar::Null);
|
indent(document(), cursor, QChar::Null);
|
||||||
@@ -1558,8 +1575,6 @@ int CPPEditor::paragraphSeparatorAboutToBeInserted(QTextCursor &cursor)
|
|||||||
m_allowSkippingOfBlockEnd = true;
|
m_allowSkippingOfBlockEnd = true;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CPPEditor::contextAllowsAutoParentheses(const QTextCursor &cursor,
|
bool CPPEditor::contextAllowsAutoParentheses(const QTextCursor &cursor,
|
||||||
const QString &textToInsert) const
|
const QString &textToInsert) const
|
||||||
|
|||||||
Reference in New Issue
Block a user