aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/cplusplus
diff options
context:
space:
mode:
authorDavid Schulz <[email protected]>2016-06-10 15:13:38 +0200
committerDavid Schulz <[email protected]>2016-06-21 11:56:56 +0000
commit675060724453fc2a5d12431b656fdbb599e529f6 (patch)
treecbf5a1fc06919089d4028bd31c6ae7e15ee575b6 /src/libs/cplusplus
parent08dcad9c829abfbc592d6a4628d091d942a87c0f (diff)
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 <[email protected]> Reviewed-by: Eike Ziller <[email protected]> Reviewed-by: Nikolai Kosjar <[email protected]> Reviewed-by: David Schulz <[email protected]>
Diffstat (limited to 'src/libs/cplusplus')
-rw-r--r--src/libs/cplusplus/MatchingText.cpp18
-rw-r--r--src/libs/cplusplus/MatchingText.h4
2 files changed, 12 insertions, 10 deletions
diff --git a/src/libs/cplusplus/MatchingText.cpp b/src/libs/cplusplus/MatchingText.cpp
index e4266653f94..08ea34c9182 100644
--- a/src/libs/cplusplus/MatchingText.cpp
+++ b/src/libs/cplusplus/MatchingText.cpp
@@ -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;
}
diff --git a/src/libs/cplusplus/MatchingText.h b/src/libs/cplusplus/MatchingText.h
index c93488c8ec8..0f861d152d0 100644
--- a/src/libs/cplusplus/MatchingText.h
+++ b/src/libs/cplusplus/MatchingText.h
@@ -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);
};