C++: support smart splitting of strings.

If 'enter' is pressed while the cursor is in the middle of a string,
the string is ended at the current cursor position, and a new string
is started on the next line.  This makes it very easy to split a long
string onto multiple lines.

In addition, Shift+Enter insert an escape in the string, to continue the
string at the beginning of next line.

A setting can be used to enable or disable this option.

Change-Id: Ia5f3c6989fc00d40d06bc4fe1182fe8b1318f565
Reviewed-by: Francois Ferrand <thetypz@gmail.com>
Reviewed-by: hjk <hjk121@nokiamail.com>
This commit is contained in:
Francois Ferrand
2014-09-29 18:19:38 +02:00
committed by hjk
parent 82d9cf4146
commit 32b960db47
10 changed files with 162 additions and 63 deletions

View File

@@ -85,6 +85,37 @@ static bool isInCommentHelper(const QTextCursor &cursor, Token *retToken = 0)
return tk.isComment();
}
static bool isInStringHelper(const QTextCursor &cursor, Token *retToken = 0)
{
LanguageFeatures features;
features.qtEnabled = false;
features.qtKeywordsEnabled = false;
features.qtMocRunEnabled = false;
features.cxx11Enabled = true;
features.c99Enabled = true;
SimpleLexer tokenize;
tokenize.setLanguageFeatures(features);
const int prevState = BackwardsScanner::previousBlockState(cursor.block()) & 0xFF;
const QList<Token> tokens = tokenize(cursor.block().text(), prevState);
const unsigned pos = cursor.selectionEnd() - cursor.block().position();
if (tokens.isEmpty() || pos < tokens.first().utf16charsBegin())
return prevState > 0;
if (pos >= tokens.last().utf16charsEnd()) {
const Token tk = tokens.last();
return tk.isStringLiteral() && prevState > 0;
}
Token tk = tokenAtPosition(tokens, pos);
if (retToken)
*retToken = tk;
return tk.isStringLiteral();
}
bool CppAutoCompleter::contextAllowsAutoParentheses(const QTextCursor &cursor,
const QString &textToInsert) const
{
@@ -124,6 +155,11 @@ bool CppAutoCompleter::isInComment(const QTextCursor &cursor) const
return isInCommentHelper(cursor);
}
bool CppAutoCompleter::isInString(const QTextCursor &cursor) const
{
return isInStringHelper(cursor);
}
QString CppAutoCompleter::insertMatchingBrace(const QTextCursor &cursor,
const QString &text,
QChar la,