Editor: Skip auto completed character only if it was recently inserted.

This means you can skip automatically inserted characters as long as you
don't explicitly move the text cursor and the editor doesn't lose the
focus. This will be visualized by highlighting the automatically
inserted character as long as you can perform the skipping.

This will reduce unexpected skipping in the case a cursor was explicitly
placed before an closing brace and a closing brace is typed.

Change-Id: I28e29e79ba10c9c48e8bc8817405fea630cca9bd
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
Reviewed-by: David Schulz <david.schulz@theqtcompany.com>
This commit is contained in:
David Schulz
2016-06-10 15:13:38 +02:00
committed by David Schulz
parent 08dcad9c82
commit 6750607244
25 changed files with 182 additions and 58 deletions

View File

@@ -455,6 +455,7 @@ public:
QPointer<TextEditorAnimator> m_autocompleteAnimator;
bool m_animateAutoComplete = true;
bool m_highlightAutoComplete = true;
bool m_skipAutoCompletedText = true;
bool m_keepAutoCompletionHighlight = false;
QTextCursor m_autoCompleteHighlightPos;
@@ -2392,8 +2393,11 @@ void TextEditorWidget::keyPressEvent(QKeyEvent *e)
// only go here if control is not pressed, except if also alt is pressed
// because AltGr maps to Alt + Ctrl
QTextCursor cursor = textCursor();
const QString &autoText = inOverwriteMode
? QString() : autoCompleter()->autoComplete(cursor, eventText);
QString autoText;
if (!inOverwriteMode) {
autoText = autoCompleter()->autoComplete(cursor, eventText,
d->m_skipAutoCompletedText && cursor == d->m_autoCompleteHighlightPos);
}
const bool cursorWithinSnippet = d->snippetCheckCursor(cursor);
QChar electricChar;
@@ -6566,6 +6570,7 @@ void TextEditorWidget::setCompletionSettings(const CompletionSettings &completio
d->m_autoCompleter->setSurroundWithQuotesEnabled(completionSettings.m_surroundingAutoQuotes);
d->m_animateAutoComplete = completionSettings.m_animateAutoComplete;
d->m_highlightAutoComplete = completionSettings.m_highlightAutoComplete;
d->m_skipAutoCompletedText = completionSettings.m_skipAutoCompletedText;
}
void TextEditorWidget::setExtraEncodingSettings(const ExtraEncodingSettings &extraEncodingSettings)
@@ -7032,6 +7037,13 @@ void TextEditorWidget::keepAutoCompletionHighlight(bool keepHighlight)
d->m_keepAutoCompletionHighlight = keepHighlight;
}
void TextEditorWidget::setAutoCompleteSkipPosition(const QTextCursor &cursor)
{
QTextCursor tc = cursor;
tc.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor);
d->autocompleterHighlight(tc);
}
int BaseTextEditor::currentLine() const
{
return editorWidget()->textCursor().blockNumber() + 1;