forked from qt-creator/qt-creator
C++ editor: Use the new indenter to make indenting selections fast.
This commit is contained in:
@@ -1512,14 +1512,9 @@ bool CPPEditor::isInComment(const QTextCursor &cursor) const
|
|||||||
return false;
|
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;
|
CppTools::QtStyleCodeFormatter codeFormatter;
|
||||||
|
|
||||||
codeFormatter.setIndentSize(ts.m_indentSize);
|
codeFormatter.setIndentSize(ts.m_indentSize);
|
||||||
codeFormatter.setTabSize(ts.m_tabSize);
|
codeFormatter.setTabSize(ts.m_tabSize);
|
||||||
if (ts.m_indentBraces && ts.m_doubleIndentBlocks) { // gnu style
|
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.setIndentDeclarationBraces(false);
|
||||||
codeFormatter.setIndentDeclarationMembers(true);
|
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);
|
codeFormatter.updateStateUntil(block);
|
||||||
const int depth = codeFormatter.indentFor(block);
|
const int depth = codeFormatter.indentFor(block);
|
||||||
ts.indentLine(block, depth);
|
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)
|
bool CPPEditor::event(QEvent *e)
|
||||||
{
|
{
|
||||||
switch (e->type()) {
|
switch (e->type()) {
|
||||||
|
|||||||
@@ -237,6 +237,7 @@ private:
|
|||||||
bool sortedMethodOverview() const;
|
bool sortedMethodOverview() const;
|
||||||
CPlusPlus::Symbol *findDefinition(CPlusPlus::Symbol *symbol, const CPlusPlus::Snapshot &snapshot);
|
CPlusPlus::Symbol *findDefinition(CPlusPlus::Symbol *symbol, const CPlusPlus::Snapshot &snapshot);
|
||||||
virtual void indentBlock(QTextDocument *doc, QTextBlock block, QChar typedChar);
|
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,
|
TextEditor::ITextEditor *openCppEditorAt(const QString &fileName, int line,
|
||||||
int column = 0);
|
int column = 0);
|
||||||
|
|||||||
@@ -476,6 +476,8 @@ protected:
|
|||||||
*/
|
*/
|
||||||
virtual bool openLink(const Link &link);
|
virtual bool openLink(const Link &link);
|
||||||
|
|
||||||
|
void maybeClearSomeExtraSelections(const QTextCursor &cursor);
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
virtual void slotUpdateExtraAreaWidth();
|
virtual void slotUpdateExtraAreaWidth();
|
||||||
virtual void slotModificationChanged(bool);
|
virtual void slotModificationChanged(bool);
|
||||||
@@ -500,8 +502,6 @@ private:
|
|||||||
void updateHighlights();
|
void updateHighlights();
|
||||||
void updateCurrentLineHighlight();
|
void updateCurrentLineHighlight();
|
||||||
|
|
||||||
void maybeClearSomeExtraSelections(const QTextCursor &cursor);
|
|
||||||
|
|
||||||
void drawFoldingMarker(QPainter *painter, const QPalette &pal,
|
void drawFoldingMarker(QPainter *painter, const QPalette &pal,
|
||||||
const QRect &rect,
|
const QRect &rect,
|
||||||
bool expanded,
|
bool expanded,
|
||||||
|
|||||||
Reference in New Issue
Block a user