aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/cplusplus
diff options
context:
space:
mode:
authorDavid Schulz <[email protected]>2016-04-14 09:00:05 +0200
committerDavid Schulz <[email protected]>2016-05-25 13:55:50 +0000
commit7595aaa227305950c5ce03c7a636a340671400ce (patch)
treebda4fa5a864b5c6914e0ca59fbd37ab82ef5d6f4 /src/libs/cplusplus
parent94fc57c00521e9b56d7b88759831a82cf9bff67e (diff)
Editor: Separate auto insert brace and quote magic.
To allow enabling/disabling both features separately. Change-Id: Ica154e3b400823de7cf22daf006958802d751c64 Reviewed-by: Nikolai Kosjar <[email protected]>
Diffstat (limited to 'src/libs/cplusplus')
-rw-r--r--src/libs/cplusplus/MatchingText.cpp72
-rw-r--r--src/libs/cplusplus/MatchingText.h6
2 files changed, 54 insertions, 24 deletions
diff --git a/src/libs/cplusplus/MatchingText.cpp b/src/libs/cplusplus/MatchingText.cpp
index 2fdcbab9f69..1d88f8e8bff 100644
--- a/src/libs/cplusplus/MatchingText.cpp
+++ b/src/libs/cplusplus/MatchingText.cpp
@@ -151,6 +151,11 @@ bool MatchingText::contextAllowsAutoParentheses(const QTextCursor &cursor,
return true;
}
+bool MatchingText::contextAllowsAutoQuotes(const QTextCursor &cursor, const QString &textToInsert)
+{
+ return !textToInsert.isEmpty() && !isInCommentHelper(cursor);
+}
+
bool MatchingText::contextAllowsElectricCharacters(const QTextCursor &cursor)
{
Token token;
@@ -250,36 +255,21 @@ bool MatchingText::isInStringHelper(const QTextCursor &cursor)
}
QString MatchingText::insertMatchingBrace(const QTextCursor &cursor, const QString &textToProcess,
- QChar la, int *skippedChars)
+ QChar /*lookAhead*/, int *skippedChars)
{
+ if (textToProcess.isEmpty())
+ return QString();
+
QTextCursor tc = cursor;
QString text = textToProcess;
const QString blockText = tc.block().text().mid(tc.positionInBlock());
const QString trimmedBlockText = blockText.trimmed();
- if (!textToProcess.isEmpty()) {
- if (!isQuote(textToProcess.at(0)) || !isEscaped(tc)) {
- *skippedChars = countSkippedChars(blockText, textToProcess);
- if (*skippedChars != 0) {
- tc.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, *skippedChars);
- text = textToProcess.mid(*skippedChars);
- }
- }
- }
-
- if (text.isEmpty() || !shouldInsertMatchingText(la))
- return QString();
-
- BackwardsScanner tk(tc, LanguageFeatures::defaultFeatures(), MAX_NUM_LINES,
- textToProcess.left(*skippedChars));
- const QChar ch0 = text.at(0);
- if (isQuote(ch0)) {
- if (text.length() != 1)
- qWarning() << Q_FUNC_INFO << "handle event compression";
- if (insertQuote(ch0, tk))
- return ch0;
- return QString();
+ *skippedChars = countSkippedChars(blockText, textToProcess);
+ if (*skippedChars != 0) {
+ tc.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, *skippedChars);
+ text = textToProcess.mid(*skippedChars);
}
QString result;
@@ -294,6 +284,42 @@ QString MatchingText::insertMatchingBrace(const QTextCursor &cursor, const QStri
return result;
}
+QString MatchingText::insertMatchingQuote(const QTextCursor &cursor, const QString &textToProcess,
+ QChar lookAhead, int *skippedChars)
+{
+ if (textToProcess.isEmpty())
+ return QString();
+
+ QTextCursor tc = cursor;
+ QString text = textToProcess;
+
+ if (!isEscaped(tc)) {
+ const QString blockText = tc.block().text().mid(tc.positionInBlock());
+ *skippedChars = countSkippedChars(blockText, textToProcess);
+ if (*skippedChars != 0) {
+ tc.movePosition(QTextCursor::NextCharacter, QTextCursor::MoveAnchor, *skippedChars);
+ text = textToProcess.mid(*skippedChars);
+ }
+ }
+
+ if (!shouldInsertMatchingText(lookAhead))
+ return QString();
+
+ if (!text.isEmpty()) {
+ const QChar ch = text.at(0);
+ if (!isQuote(ch))
+ return QString();
+ if (text.length() != 1)
+ qWarning() << Q_FUNC_INFO << "handle event compression";
+
+ BackwardsScanner tk(tc, LanguageFeatures::defaultFeatures(), MAX_NUM_LINES,
+ textToProcess.left(*skippedChars));
+ if (insertQuote(ch, tk))
+ return ch;
+ }
+ return QString();
+}
+
static bool shouldInsertNewline(const QTextCursor &tc)
{
QTextDocument *doc = tc.document();
diff --git a/src/libs/cplusplus/MatchingText.h b/src/libs/cplusplus/MatchingText.h
index b13ede23fc9..c93488c8ec8 100644
--- a/src/libs/cplusplus/MatchingText.h
+++ b/src/libs/cplusplus/MatchingText.h
@@ -38,6 +38,8 @@ class CPLUSPLUS_EXPORT MatchingText
public:
static bool contextAllowsAutoParentheses(const QTextCursor &cursor,
const QString &textToInsert);
+ static bool contextAllowsAutoQuotes(const QTextCursor &cursor,
+ const QString &textToInsert);
static bool contextAllowsElectricCharacters(const QTextCursor &cursor);
static bool shouldInsertMatchingText(const QTextCursor &tc);
@@ -47,7 +49,9 @@ public:
static bool isInStringHelper(const QTextCursor &cursor);
static QString insertMatchingBrace(const QTextCursor &tc, const QString &text,
- QChar la, int *skippedChars);
+ QChar lookAhead, int *skippedChars);
+ static QString insertMatchingQuote(const QTextCursor &tc, const QString &text,
+ QChar lookAhead, int *skippedChars);
static QString insertParagraphSeparator(const QTextCursor &tc);
};