Commit e086c67e authored by Christian Kamm's avatar Christian Kamm
Browse files

C++ editor: Use the new indenter to make indenting selections fast.

parent 74ed3e8a
......@@ -1512,14 +1512,9 @@ bool CPPEditor::isInComment(const QTextCursor &cursor) const
return false;
}
void CPPEditor::indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar)
static CppTools::QtStyleCodeFormatter setupCodeFormatter(const TextEditor::TabSettings &ts)
{
Q_UNUSED(doc)
Q_UNUSED(typedChar)
const TabSettings &ts = tabSettings();
CppTools::QtStyleCodeFormatter codeFormatter;
codeFormatter.setIndentSize(ts.m_indentSize);
codeFormatter.setTabSize(ts.m_tabSize);
if (ts.m_indentBraces && ts.m_doubleIndentBlocks) { // gnu style
......@@ -1538,12 +1533,46 @@ void CPPEditor::indentBlock(QTextDocument *doc, QTextBlock block, QChar typedCha
codeFormatter.setIndentDeclarationBraces(false);
codeFormatter.setIndentDeclarationMembers(true);
}
return codeFormatter;
}
void CPPEditor::indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar)
{
Q_UNUSED(doc)
Q_UNUSED(typedChar)
const TabSettings &ts = tabSettings();
CppTools::QtStyleCodeFormatter codeFormatter = setupCodeFormatter(ts);
codeFormatter.updateStateUntil(block);
const int depth = codeFormatter.indentFor(block);
ts.indentLine(block, depth);
}
void CPPEditor::indent(QTextDocument *doc, const QTextCursor &cursor, QChar typedChar)
{
Q_UNUSED(doc)
Q_UNUSED(typedChar)
maybeClearSomeExtraSelections(cursor);
if (cursor.hasSelection()) {
QTextBlock block = doc->findBlock(cursor.selectionStart());
const QTextBlock end = doc->findBlock(cursor.selectionEnd()).next();
const TabSettings &ts = tabSettings();
CppTools::QtStyleCodeFormatter codeFormatter = setupCodeFormatter(ts);
codeFormatter.updateStateUntil(block);
do {
ts.indentLine(block, codeFormatter.indentFor(block));
codeFormatter.updateLineStateChange(block);
block = block.next();
} while (block.isValid() && block != end);
} else {
indentBlock(doc, cursor.block(), typedChar);
}
}
bool CPPEditor::event(QEvent *e)
{
switch (e->type()) {
......
......@@ -237,6 +237,7 @@ private:
bool sortedMethodOverview() const;
CPlusPlus::Symbol *findDefinition(CPlusPlus::Symbol *symbol, const CPlusPlus::Snapshot &snapshot);
virtual void indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar);
virtual void indent(QTextDocument *doc, const QTextCursor &cursor, QChar typedChar);
TextEditor::ITextEditor *openCppEditorAt(const QString &fileName, int line,
int column = 0);
......
......@@ -476,6 +476,8 @@ protected:
*/
virtual bool openLink(const Link &link);
void maybeClearSomeExtraSelections(const QTextCursor &cursor);
protected slots:
virtual void slotUpdateExtraAreaWidth();
virtual void slotModificationChanged(bool);
......@@ -500,8 +502,6 @@ private:
void updateHighlights();
void updateCurrentLineHighlight();
void maybeClearSomeExtraSelections(const QTextCursor &cursor);
void drawFoldingMarker(QPainter *painter, const QPalette &pal,
const QRect &rect,
bool expanded,
......
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