forked from qt-creator/qt-creator
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:
committed by
David Schulz
parent
08dcad9c82
commit
6750607244
@@ -255,7 +255,7 @@ bool MatchingText::isInStringHelper(const QTextCursor &cursor)
|
||||
}
|
||||
|
||||
QString MatchingText::insertMatchingBrace(const QTextCursor &cursor, const QString &textToProcess,
|
||||
QChar /*lookAhead*/, int *skippedChars)
|
||||
QChar /*lookAhead*/, bool skipChars, int *skippedChars)
|
||||
{
|
||||
if (textToProcess.isEmpty())
|
||||
return QString();
|
||||
@@ -266,10 +266,12 @@ QString MatchingText::insertMatchingBrace(const QTextCursor &cursor, const QStri
|
||||
const QString blockText = tc.block().text().mid(tc.positionInBlock());
|
||||
const QString trimmedBlockText = blockText.trimmed();
|
||||
|
||||
*skippedChars = countSkippedChars(blockText, textToProcess);
|
||||
if (*skippedChars != 0) {
|
||||
tc.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, *skippedChars);
|
||||
text = textToProcess.mid(*skippedChars);
|
||||
if (skipChars) {
|
||||
*skippedChars = countSkippedChars(blockText, textToProcess);
|
||||
if (*skippedChars != 0) {
|
||||
tc.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, *skippedChars);
|
||||
text = textToProcess.mid(*skippedChars);
|
||||
}
|
||||
}
|
||||
|
||||
QString result;
|
||||
@@ -285,7 +287,7 @@ QString MatchingText::insertMatchingBrace(const QTextCursor &cursor, const QStri
|
||||
}
|
||||
|
||||
QString MatchingText::insertMatchingQuote(const QTextCursor &cursor, const QString &textToProcess,
|
||||
QChar lookAhead, int *skippedChars)
|
||||
QChar lookAhead, bool skipChars, int *skippedChars)
|
||||
{
|
||||
if (textToProcess.isEmpty())
|
||||
return QString();
|
||||
@@ -293,7 +295,7 @@ QString MatchingText::insertMatchingQuote(const QTextCursor &cursor, const QStri
|
||||
QTextCursor tc = cursor;
|
||||
QString text = textToProcess;
|
||||
|
||||
if (!isEscaped(tc)) {
|
||||
if (skipChars && !isEscaped(tc)) {
|
||||
const QString blockText = tc.block().text().mid(tc.positionInBlock());
|
||||
*skippedChars = countSkippedChars(blockText, textToProcess);
|
||||
if (*skippedChars != 0) {
|
||||
@@ -313,7 +315,7 @@ QString MatchingText::insertMatchingQuote(const QTextCursor &cursor, const QStri
|
||||
qWarning() << Q_FUNC_INFO << "handle event compression";
|
||||
|
||||
BackwardsScanner tk(tc, LanguageFeatures::defaultFeatures(), MAX_NUM_LINES,
|
||||
textToProcess.left(*skippedChars));
|
||||
textToProcess.left(skippedChars ? *skippedChars : 0));
|
||||
if (insertQuote(ch, tk))
|
||||
return ch;
|
||||
}
|
||||
|
||||
@@ -49,9 +49,9 @@ public:
|
||||
static bool isInStringHelper(const QTextCursor &cursor);
|
||||
|
||||
static QString insertMatchingBrace(const QTextCursor &tc, const QString &text,
|
||||
QChar lookAhead, int *skippedChars);
|
||||
QChar lookAhead, bool skipChars, int *skippedChars);
|
||||
static QString insertMatchingQuote(const QTextCursor &tc, const QString &text,
|
||||
QChar lookAhead, int *skippedChars);
|
||||
QChar lookAhead, bool skipChars, int *skippedChars);
|
||||
static QString insertParagraphSeparator(const QTextCursor &tc);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user