ClangFormat: Add cursor position to the indenter interface

Sometimes it's imnportant where the cursor currently is
to properly format the code without affecting the current line.

Change-Id: I8b1fb11d2303adb5f960c7cb80a0ed2e6e45010f
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
Ivan Donchevskii
2019-01-28 08:11:20 +01:00
parent 80fb0178fd
commit 1dee275f58
24 changed files with 185 additions and 95 deletions

View File

@@ -2491,7 +2491,7 @@ void TextEditorWidget::keyPressEvent(QKeyEvent *e)
--extraBlocks;
ensureVisible.movePosition(QTextCursor::NextBlock);
if (tps.m_autoIndent)
d->m_document->autoIndent(ensureVisible);
d->m_document->autoIndent(ensureVisible, QChar::Null, cursorPosition);
else if (!previousIndentationString.isEmpty())
ensureVisible.insertText(previousIndentationString);
if (d->m_animateAutoComplete || d->m_highlightAutoComplete) {
@@ -2773,7 +2773,7 @@ void TextEditorWidget::keyPressEvent(QKeyEvent *e)
cursor.setPosition(pos, QTextCursor::KeepAnchor);
}
if (!electricChar.isNull() && d->m_autoCompleter->contextAllowsElectricCharacters(cursor))
d->m_document->autoIndent(cursor, electricChar);
d->m_document->autoIndent(cursor, electricChar, cursor.position());
if (!autoText.isEmpty())
cursor.setPosition(autoText.length() == 1 ? cursor.position() : cursor.anchor());