forked from qt-creator/qt-creator
C++: Only reindent on electric characters if indent wasn't user-changed.
This should make the indenter less strict and annoying for non-standard indentation styles. Reviewed-by: Roberto Raggi
This commit is contained in:
@@ -1494,13 +1494,21 @@ bool CPPEditor::isInComment(const QTextCursor &cursor) const
|
|||||||
void CPPEditor::indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar)
|
void CPPEditor::indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar)
|
||||||
{
|
{
|
||||||
Q_UNUSED(doc)
|
Q_UNUSED(doc)
|
||||||
Q_UNUSED(typedChar)
|
|
||||||
|
|
||||||
const TabSettings &ts = tabSettings();
|
const TabSettings &ts = tabSettings();
|
||||||
CppTools::QtStyleCodeFormatter codeFormatter(ts);
|
CppTools::QtStyleCodeFormatter codeFormatter(ts);
|
||||||
|
|
||||||
codeFormatter.updateStateUntil(block);
|
codeFormatter.updateStateUntil(block);
|
||||||
const int depth = codeFormatter.indentFor(block);
|
const int depth = codeFormatter.indentFor(block);
|
||||||
|
|
||||||
|
// only reindent the current line when typing electric characters if the
|
||||||
|
// indent is the same it would be if the line were empty
|
||||||
|
if (isElectricCharacter(typedChar)) {
|
||||||
|
const int newlineIndent = codeFormatter.indentForNewLineAfter(block.previous());
|
||||||
|
if (ts.indentationColumn(block.text()) != newlineIndent)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ts.indentLine(block, depth);
|
ts.indentLine(block, depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -470,6 +470,12 @@ int CodeFormatter::indentFor(const QTextBlock &block)
|
|||||||
return m_indentDepth;
|
return m_indentDepth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CodeFormatter::indentForNewLineAfter(const QTextBlock &block)
|
||||||
|
{
|
||||||
|
restoreCurrentState(block);
|
||||||
|
return m_indentDepth;
|
||||||
|
}
|
||||||
|
|
||||||
void CodeFormatter::updateStateUntil(const QTextBlock &endBlock)
|
void CodeFormatter::updateStateUntil(const QTextBlock &endBlock)
|
||||||
{
|
{
|
||||||
QStack<State> previousState = initialState();
|
QStack<State> previousState = initialState();
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ public:
|
|||||||
void updateLineStateChange(const QTextBlock &block);
|
void updateLineStateChange(const QTextBlock &block);
|
||||||
|
|
||||||
int indentFor(const QTextBlock &block);
|
int indentFor(const QTextBlock &block);
|
||||||
|
int indentForNewLineAfter(const QTextBlock &block);
|
||||||
|
|
||||||
void setTabSize(int tabSize);
|
void setTabSize(int tabSize);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user