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

@@ -73,11 +73,13 @@ bool CMakeAutoCompleter::isInString(const QTextCursor &cursor) const
return inString;
}
QString CMakeAutoCompleter::insertMatchingBrace(const QTextCursor &cursor, const QString &text,
QChar lookAhead, int *skippedChars) const
QString CMakeAutoCompleter::insertMatchingBrace(const QTextCursor &cursor,
const QString &text,
QChar lookAhead,
bool skipChars,
int *skippedChars) const
{
Q_UNUSED(cursor)
Q_UNUSED(skippedChars)
if (text.isEmpty())
return QString();
const QChar current = text.at(0);
@@ -86,7 +88,7 @@ QString CMakeAutoCompleter::insertMatchingBrace(const QTextCursor &cursor, const
return QStringLiteral(")");
case ')':
if (current == lookAhead)
if (current == lookAhead && skipChars)
++*skippedChars;
break;
@@ -97,17 +99,21 @@ QString CMakeAutoCompleter::insertMatchingBrace(const QTextCursor &cursor, const
return QString();
}
QString CMakeAutoCompleter::insertMatchingQuote(const QTextCursor &cursor, const QString &text,
QChar lookAhead, int *skippedChars) const
QString CMakeAutoCompleter::insertMatchingQuote(const QTextCursor &cursor,
const QString &text,
QChar lookAhead,
bool skipChars,
int *skippedChars) const
{
Q_UNUSED(cursor)
static const QChar quote(QLatin1Char('"'));
if (text.isEmpty() || text != quote)
return QString();
if (lookAhead != quote)
return quote;
++*skippedChars;
return QString();
if (lookAhead == quote && skipChars) {
++*skippedChars;
return QString();
}
return quote;
}
int CMakeAutoCompleter::paragraphSeparatorAboutToBeInserted(QTextCursor &cursor, const TextEditor::TabSettings &tabSettings)