Editor: Skip auto inserted characters with tab

Fixes: QTCREATORBUG-12641
Change-Id: I9800b939118d1e46d202454a66729cd81d2c08b3
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2020-09-21 11:43:41 +02:00
parent eb6a2f2b89
commit f6b3f41d19
2 changed files with 16 additions and 1 deletions

View File

@@ -318,7 +318,7 @@ In addition, Shift+Enter inserts an escape character at the cursor position and
<item>
<widget class="QCheckBox" name="skipAutoComplete">
<property name="toolTip">
<string>Skip automatically inserted character if re-typed manually after completion.</string>
<string>Skip automatically inserted character if re-typed manually after completion or by pressing tab.</string>
</property>
<property name="text">
<string>Skip automatically inserted character when typing</string>

View File

@@ -2484,6 +2484,21 @@ void TextEditorWidget::keyPressEvent(QKeyEvent *e)
return;
}
QTextCursor cursor = textCursor();
if (d->m_skipAutoCompletedText && e->key() == Qt::Key_Tab) {
bool skippedAutoCompletedText = false;
while (!d->m_autoCompleteHighlightPos.isEmpty()
&& d->m_autoCompleteHighlightPos.last().selectionStart() == cursor.position()) {
skippedAutoCompletedText = true;
cursor.setPosition(d->m_autoCompleteHighlightPos.last().selectionEnd());
d->m_autoCompleteHighlightPos.pop_back();
}
if (skippedAutoCompletedText) {
setTextCursor(cursor);
e->accept();
d->updateAutoCompleteHighlight();
return;
}
}
int newPosition;
if (d->m_document->typingSettings().tabShouldIndent(document(), cursor, &newPosition)) {
if (newPosition != cursor.position() && !cursor.hasSelection()) {