forked from qt-creator/qt-creator
Clang: Use clang-format for indentation
This is the new experimental plugin based on LibFormat. It replaces the default indenter for CppEditorDocument and applies clang-format after the CR or the set of 'electric' characters. Uses the global .clang-format kept in QtC settings or the one for current project. Both can be configured. For indentation some style modifications and code manipulations are done to prevent line shrinking when it's not expected. Manual indentation uses unmodified style from .clang-format file. Change-Id: I6279b805e418e1804b553efa615f5c843f395a58 Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
@@ -2451,7 +2451,7 @@ void TextEditorWidget::keyPressEvent(QKeyEvent *e)
|
||||
}
|
||||
|
||||
QTextCursor cursor = textCursor();
|
||||
const TabSettings &ts = d->m_document->tabSettings();
|
||||
const TabSettings ts = d->m_document->tabSettings();
|
||||
const TypingSettings &tps = d->m_document->typingSettings();
|
||||
cursor.beginEditBlock();
|
||||
|
||||
@@ -2474,6 +2474,7 @@ void TextEditorWidget::keyPressEvent(QKeyEvent *e)
|
||||
e->accept();
|
||||
|
||||
if (extraBlocks > 0) {
|
||||
const int cursorPosition = cursor.position();
|
||||
QTextCursor ensureVisible = cursor;
|
||||
while (extraBlocks > 0) {
|
||||
--extraBlocks;
|
||||
@@ -2491,6 +2492,7 @@ void TextEditorWidget::keyPressEvent(QKeyEvent *e)
|
||||
}
|
||||
}
|
||||
setTextCursor(ensureVisible);
|
||||
cursor.setPosition(cursorPosition);
|
||||
}
|
||||
|
||||
setTextCursor(cursor);
|
||||
@@ -3738,7 +3740,7 @@ QString TextEditorWidgetPrivate::copyBlockSelection()
|
||||
if (!m_inBlockSelectionMode)
|
||||
return QString();
|
||||
QString selection;
|
||||
const TabSettings &ts = m_document->tabSettings();
|
||||
const TabSettings ts = m_document->tabSettings();
|
||||
QTextBlock block =
|
||||
m_document->document()->findBlockByNumber(m_blockSelection.firstBlockNumber());
|
||||
const QTextBlock &lastBlock =
|
||||
@@ -3780,7 +3782,7 @@ QString TextEditorWidgetPrivate::copyBlockSelection()
|
||||
|
||||
void TextEditorWidgetPrivate::setCursorToColumn(QTextCursor &cursor, int column, QTextCursor::MoveMode moveMode)
|
||||
{
|
||||
const TabSettings &ts = m_document->tabSettings();
|
||||
const TabSettings ts = m_document->tabSettings();
|
||||
int offset = 0;
|
||||
const int cursorPosition = cursor.position();
|
||||
const int pos = ts.positionAtColumn(cursor.block().text(), column, &offset);
|
||||
@@ -3841,7 +3843,7 @@ void TextEditorWidgetPrivate::insertIntoBlockSelection(const QString &text)
|
||||
- m_blockSelection.firstBlockNumber();
|
||||
const int textNewLineCount = text.count(QLatin1Char('\n')) ;
|
||||
QStringList textLines = text.split(QLatin1Char('\n'));
|
||||
const TabSettings &ts = m_document->tabSettings();
|
||||
const TabSettings ts = m_document->tabSettings();
|
||||
int textLength = 0;
|
||||
const QStringList::const_iterator endLine = textLines.constEnd();
|
||||
for (QStringList::const_iterator textLine = textLines.constBegin(); textLine != endLine; ++textLine)
|
||||
@@ -3903,7 +3905,7 @@ void TextEditorWidgetPrivate::removeBlockSelection()
|
||||
cursor.clearSelection();
|
||||
cursor.beginEditBlock();
|
||||
|
||||
const TabSettings &ts = m_document->tabSettings();
|
||||
const TabSettings ts = m_document->tabSettings();
|
||||
QTextBlock block = m_document->document()->findBlockByNumber(m_blockSelection.firstBlockNumber());
|
||||
const QTextBlock &lastBlock = m_document->document()->findBlockByNumber(m_blockSelection.lastBlockNumber());
|
||||
for (;;) {
|
||||
@@ -3930,7 +3932,7 @@ void TextEditorWidgetPrivate::removeBlockSelection()
|
||||
|
||||
void TextEditorWidgetPrivate::enableBlockSelection(const QTextCursor &cursor)
|
||||
{
|
||||
const TabSettings &ts = m_document->tabSettings();
|
||||
const TabSettings ts = m_document->tabSettings();
|
||||
const QTextBlock &positionTextBlock = cursor.block();
|
||||
int positionBlock = positionTextBlock.blockNumber();
|
||||
int positionColumn = ts.columnAt(positionTextBlock.text(),
|
||||
@@ -4350,7 +4352,7 @@ void TextEditorWidgetPrivate::paintFindScope(const PaintEventData &data, QPainte
|
||||
&& block.position() <= m_findScopeEnd.block().position()) {
|
||||
QTextLayout *layout = block.layout();
|
||||
QString text = block.text();
|
||||
const TabSettings &ts = m_document->tabSettings();
|
||||
const TabSettings ts = m_document->tabSettings();
|
||||
qreal spacew = QFontMetricsF(q->font()).width(QLatin1Char(' '));
|
||||
|
||||
int offset = 0;
|
||||
@@ -4440,7 +4442,7 @@ void TextEditorWidgetPrivate::paintBlockSelection(const PaintEventData &data, QP
|
||||
QTextLayout *layout = data.block.layout();
|
||||
QRectF blockBoundingRect = q->blockBoundingRect(data.block).translated(data.offset);
|
||||
QString text = data.block.text();
|
||||
const TabSettings &tabSettings = m_document->tabSettings();
|
||||
const TabSettings tabSettings = m_document->tabSettings();
|
||||
const qreal spacew = QFontMetricsF(q->font()).width(QLatin1Char(' '));
|
||||
const int cursorw = q->overwriteMode() ? QFontMetrics(q->font()).width(QLatin1Char(' '))
|
||||
: q->cursorWidth();
|
||||
@@ -4726,7 +4728,7 @@ void TextEditorWidgetPrivate::setupSelections(const PaintEventData &data,
|
||||
o.format = range.format;
|
||||
if (i == data.blockSelectionIndex) {
|
||||
QString text = data.block.text();
|
||||
const TabSettings &ts = m_document->tabSettings();
|
||||
const TabSettings ts = m_document->tabSettings();
|
||||
o.start = ts.positionAtColumn(text, m_blockSelection.firstVisualColumn());
|
||||
o.length = ts.positionAtColumn(text, m_blockSelection.lastVisualColumn()) - o.start;
|
||||
}
|
||||
@@ -5511,12 +5513,13 @@ void TextEditorWidget::mouseMoveEvent(QMouseEvent *e)
|
||||
QPlainTextEdit::mouseMoveEvent(e);
|
||||
|
||||
if (e->modifiers() & Qt::AltModifier) {
|
||||
const TabSettings tabSettings = d->m_document->tabSettings();
|
||||
if (!d->m_inBlockSelectionMode) {
|
||||
if (textCursor().hasSelection()) {
|
||||
d->enableBlockSelection(textCursor());
|
||||
} else {
|
||||
const QTextCursor &cursor = cursorForPosition(e->pos());
|
||||
int column = d->m_document->tabSettings().columnAt(
|
||||
int column = tabSettings.columnAt(
|
||||
cursor.block().text(), cursor.positionInBlock());
|
||||
if (cursor.positionInBlock() == cursor.block().length()-1)
|
||||
column += (e->pos().x() - cursorRect().center().x()) / QFontMetricsF(font()).width(QLatin1Char(' '));
|
||||
@@ -5529,7 +5532,7 @@ void TextEditorWidget::mouseMoveEvent(QMouseEvent *e)
|
||||
const QTextCursor &cursor = textCursor();
|
||||
|
||||
// get visual column
|
||||
int column = d->m_document->tabSettings().columnAt(
|
||||
int column = tabSettings.columnAt(
|
||||
cursor.block().text(), cursor.positionInBlock());
|
||||
if (cursor.positionInBlock() == cursor.block().length()-1)
|
||||
column += (e->pos().x() - cursorRect().center().x()) / QFontMetricsF(font()).width(QLatin1Char(' '));
|
||||
@@ -6056,7 +6059,7 @@ void TextEditorWidgetPrivate::handleBackspaceKey()
|
||||
cursorWithinSnippet = snippetCheckCursor(snippetCursor);
|
||||
}
|
||||
|
||||
const TabSettings &tabSettings = m_document->tabSettings();
|
||||
const TabSettings tabSettings = m_document->tabSettings();
|
||||
const TypingSettings &typingSettings = m_document->typingSettings();
|
||||
|
||||
if (typingSettings.m_autoIndent
|
||||
@@ -7131,7 +7134,7 @@ void TextEditorWidget::format()
|
||||
{
|
||||
QTextCursor cursor = textCursor();
|
||||
cursor.beginEditBlock();
|
||||
d->m_document->autoIndent(cursor);
|
||||
d->m_document->autoIndent(cursor, QChar::Null, false);
|
||||
cursor.endEditBlock();
|
||||
}
|
||||
|
||||
@@ -8059,7 +8062,7 @@ QTextCursor TextBlockSelection::cursor(const TextDocument *baseTextDocument,
|
||||
if (!baseTextDocument)
|
||||
return QTextCursor();
|
||||
QTextDocument *document = baseTextDocument->document();
|
||||
const TabSettings &ts = baseTextDocument->tabSettings();
|
||||
const TabSettings ts = baseTextDocument->tabSettings();
|
||||
|
||||
int selectionAnchorColumn;
|
||||
int selectionPositionColumn;
|
||||
@@ -8119,7 +8122,7 @@ bool TextEditorWidget::inFindScope(int selectionStart, int selectionEnd)
|
||||
if (block != document()->findBlock(selectionEnd))
|
||||
return false;
|
||||
QString text = block.text();
|
||||
const TabSettings &ts = d->m_document->tabSettings();
|
||||
const TabSettings ts = d->m_document->tabSettings();
|
||||
int startPosition = ts.positionAtColumn(text, d->m_findScopeVerticalBlockSelectionFirstColumn);
|
||||
int endPosition = ts.positionAtColumn(text, d->m_findScopeVerticalBlockSelectionLastColumn);
|
||||
if (selectionStart - block.position() < startPosition)
|
||||
@@ -8246,7 +8249,7 @@ void TextEditorWidgetPrivate::transformSelection(TransformationMethod method)
|
||||
void TextEditorWidgetPrivate::transformBlockSelection(TransformationMethod method)
|
||||
{
|
||||
QTextCursor cursor = q->textCursor();
|
||||
const TabSettings &ts = m_document->tabSettings();
|
||||
const TabSettings ts = m_document->tabSettings();
|
||||
|
||||
// saved to restore the blockselection
|
||||
const int positionColumn = m_blockSelection.positionColumn;
|
||||
|
||||
Reference in New Issue
Block a user