Commit 7595aaa2 authored by David Schulz's avatar David Schulz

Editor: Separate auto insert brace and quote magic.

To allow enabling/disabling both features separately.

Change-Id: Ica154e3b400823de7cf22daf006958802d751c64
Reviewed-by: Nikolai Kosjar's avatarNikolai Kosjar <nikolai.kosjar@qt.io>
parent 94fc57c0
......@@ -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();
......
......@@ -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);
};
......
......@@ -36,7 +36,7 @@ namespace Internal {
CMakeAutoCompleter::CMakeAutoCompleter()
{
setAutoParenthesesEnabled(true);
setAutoInsertBracketsEnabled(true);
}
bool CMakeAutoCompleter::isInComment(const QTextCursor &cursor) const
......@@ -73,25 +73,20 @@ bool CMakeAutoCompleter::isInString(const QTextCursor &cursor) const
return inString;
}
QString CMakeAutoCompleter::insertMatchingBrace(const QTextCursor &cursor, const QString &text, QChar la, int *skippedChars) const
QString CMakeAutoCompleter::insertMatchingBrace(const QTextCursor &cursor, const QString &text,
QChar lookAhead, int *skippedChars) const
{
Q_UNUSED(cursor)
Q_UNUSED(skippedChars);
Q_UNUSED(skippedChars)
if (text.isEmpty())
return QString();
const QChar current = text.at(0);
switch (current.unicode()) {
case '"':
if (la != current)
return QStringLiteral("\"");
++*skippedChars;
break;
case '(':
return QStringLiteral(")");
case ')':
if (current == la)
if (current == lookAhead)
++*skippedChars;
break;
......@@ -102,6 +97,19 @@ QString CMakeAutoCompleter::insertMatchingBrace(const QTextCursor &cursor, const
return QString();
}
QString CMakeAutoCompleter::insertMatchingQuote(const QTextCursor &cursor, const QString &text,
QChar lookAhead, 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();
}
int CMakeAutoCompleter::paragraphSeparatorAboutToBeInserted(QTextCursor &cursor, const TextEditor::TabSettings &tabSettings)
{
const QString line = cursor.block().text().trimmed();
......@@ -110,13 +118,25 @@ int CMakeAutoCompleter::paragraphSeparatorAboutToBeInserted(QTextCursor &cursor,
return 0;
}
bool CMakeAutoCompleter::contextAllowsAutoParentheses(const QTextCursor &cursor, const QString &textToInsert) const
bool CMakeAutoCompleter::contextAllowsAutoBrackets(const QTextCursor &cursor,
const QString &textToInsert) const
{
if (textToInsert.isEmpty())
return false;
const QChar c = textToInsert.at(0);
if (c == QLatin1Char('(') || c == QLatin1Char(')'))
return !isInComment(cursor);
return false;
}
bool CMakeAutoCompleter::contextAllowsAutoQuotes(const QTextCursor &cursor, const QString &textToInsert) const
{
if (textToInsert.isEmpty())
return false;
const QChar c = textToInsert.at(0);
if (c == QLatin1Char('"') || c == QLatin1Char('(') || c == QLatin1Char(')'))
if (c == QLatin1Char('"'))
return !isInComment(cursor);
return false;
}
......
......@@ -39,9 +39,13 @@ public:
bool isInComment(const QTextCursor &cursor) const override;
bool isInString(const QTextCursor &cursor) const override;
QString insertMatchingBrace(const QTextCursor &cursor, const QString &text, QChar la, int *skippedChars) const override;
QString insertMatchingBrace(const QTextCursor &cursor, const QString &text,
QChar lookAhead, int *skippedChars) const override;
QString insertMatchingQuote(const QTextCursor &cursor, const QString &text,
QChar lookAhead, int *skippedChars) const override;
int paragraphSeparatorAboutToBeInserted(QTextCursor &cursor, const TextEditor::TabSettings &tabSettings) override;
bool contextAllowsAutoParentheses(const QTextCursor &cursor, const QString &textToInsert) const override;
bool contextAllowsAutoBrackets(const QTextCursor &cursor, const QString &textToInsert) const override;
bool contextAllowsAutoQuotes(const QTextCursor &cursor, const QString &textToInsert) const override;
bool contextAllowsElectricCharacters(const QTextCursor &cursor) const override;
};
......
......@@ -32,12 +32,18 @@
using namespace CppEditor;
using namespace Internal;
bool CppAutoCompleter::contextAllowsAutoParentheses(const QTextCursor &cursor,
bool CppAutoCompleter::contextAllowsAutoBrackets(const QTextCursor &cursor,
const QString &textToInsert) const
{
return CPlusPlus::MatchingText::contextAllowsAutoParentheses(cursor, textToInsert);
}
bool CppAutoCompleter::contextAllowsAutoQuotes(const QTextCursor &cursor,
const QString &textToInsert) const
{
return CPlusPlus::MatchingText::contextAllowsAutoQuotes(cursor, textToInsert);
}
bool CppAutoCompleter::contextAllowsElectricCharacters(const QTextCursor &cursor) const
{
return CPlusPlus::MatchingText::contextAllowsElectricCharacters(cursor);
......@@ -53,12 +59,16 @@ bool CppAutoCompleter::isInString(const QTextCursor &cursor) const
return CPlusPlus::MatchingText::isInStringHelper(cursor);
}
QString CppAutoCompleter::insertMatchingBrace(const QTextCursor &cursor,
const QString &text,
QChar la,
int *skippedChars) const
QString CppAutoCompleter::insertMatchingBrace(const QTextCursor &cursor, const QString &text,
QChar lookAhead, int *skippedChars) const
{
return CPlusPlus::MatchingText::insertMatchingBrace(cursor, text, lookAhead, skippedChars);
}
QString CppAutoCompleter::insertMatchingQuote(const QTextCursor &cursor, const QString &text,
QChar lookAhead, int *skippedChars) const
{
return CPlusPlus::MatchingText::insertMatchingBrace(cursor, text, la, skippedChars);
return CPlusPlus::MatchingText::insertMatchingQuote(cursor, text, lookAhead, skippedChars);
}
QString CppAutoCompleter::insertParagraphSeparator(const QTextCursor &cursor) const
......
......@@ -35,16 +35,22 @@ class CppAutoCompleter : public TextEditor::AutoCompleter
public:
CppAutoCompleter() {}
virtual bool contextAllowsAutoParentheses(const QTextCursor &cursor,
const QString &textToInsert = QString()) const;
virtual bool contextAllowsElectricCharacters(const QTextCursor &cursor) const;
virtual bool isInComment(const QTextCursor &cursor) const;
virtual bool isInString(const QTextCursor &cursor) const;
virtual QString insertMatchingBrace(const QTextCursor &cursor,
const QString &text,
QChar la,
int *skippedChars) const;
virtual QString insertParagraphSeparator(const QTextCursor &cursor) const;
bool contextAllowsAutoBrackets(const QTextCursor &cursor,
const QString &textToInsert = QString()) const override;
bool contextAllowsAutoQuotes(const QTextCursor &cursor,
const QString &textToInsert = QString()) const override;
bool contextAllowsElectricCharacters(const QTextCursor &cursor) const override;
bool isInComment(const QTextCursor &cursor) const override;
bool isInString(const QTextCursor &cursor) const override;
QString insertMatchingBrace(const QTextCursor &cursor,
const QString &text,
QChar lookAhead,
int *skippedChars) const override;
QString insertMatchingQuote(const QTextCursor &cursor,
const QString &text,
QChar lookAhead,
int *skippedChars) const override;
QString insertParagraphSeparator(const QTextCursor &cursor) const override;
};
} // Internal
......
......@@ -93,8 +93,10 @@ QWidget *CompletionSettingsPage::widget()
m_page->completionTrigger->setCurrentIndex(completionTriggerIndex);
m_page->automaticProposalTimeoutSpinBox
->setValue(completionSettings.m_automaticProposalTimeoutInMs);
m_page->autoInsertBrackets->setChecked(completionSettings.m_autoInsertBrackets);
m_page->surroundSelectedText->setChecked(completionSettings.m_surroundingAutoBrackets);
m_page->insertBrackets->setChecked(completionSettings.m_autoInsertBrackets);
m_page->surroundBrackets->setChecked(completionSettings.m_surroundingAutoBrackets);
m_page->insertQuotes->setChecked(completionSettings.m_autoInsertQuotes);
m_page->surroundQuotes->setChecked(completionSettings.m_surroundingAutoQuotes);
m_page->partiallyComplete->setChecked(completionSettings.m_partiallyComplete);
m_page->spaceAfterFunctionName->setChecked(completionSettings.m_spaceAfterFunctionName);
m_page->autoSplitStrings->setChecked(completionSettings.m_autoSplitStrings);
......@@ -119,8 +121,10 @@ void CompletionSettingsPage::apply()
completionSettings.m_completionTrigger = completionTrigger();
completionSettings.m_automaticProposalTimeoutInMs
= m_page->automaticProposalTimeoutSpinBox->value();
completionSettings.m_autoInsertBrackets = m_page->autoInsertBrackets->isChecked();
completionSettings.m_surroundingAutoBrackets = m_page->surroundSelectedText->isChecked();
completionSettings.m_autoInsertBrackets = m_page->insertBrackets->isChecked();
completionSettings.m_surroundingAutoBrackets = m_page->surroundBrackets->isChecked();
completionSettings.m_autoInsertQuotes = m_page->insertQuotes->isChecked();
completionSettings.m_surroundingAutoQuotes = m_page->surroundQuotes->isChecked();
completionSettings.m_partiallyComplete = m_page->partiallyComplete->isChecked();
completionSettings.m_spaceAfterFunctionName = m_page->spaceAfterFunctionName->isChecked();
completionSettings.m_autoSplitStrings = m_page->autoSplitStrings->isChecked();
......
......@@ -32,12 +32,18 @@
namespace GlslEditor {
namespace Internal {
bool GlslCompleter::contextAllowsAutoParentheses(const QTextCursor &cursor,
const QString &textToInsert) const
bool GlslCompleter::contextAllowsAutoBrackets(const QTextCursor &cursor,
const QString &textToInsert) const
{
return CPlusPlus::MatchingText::contextAllowsAutoParentheses(cursor, textToInsert);
}
bool GlslCompleter::contextAllowsAutoQuotes(const QTextCursor &cursor,
const QString &textToInsert) const
{
return CPlusPlus::MatchingText::contextAllowsAutoQuotes(cursor, textToInsert);
}
bool GlslCompleter::contextAllowsElectricCharacters(const QTextCursor &cursor) const
{
return CPlusPlus::MatchingText::contextAllowsElectricCharacters(cursor);
......@@ -48,12 +54,16 @@ bool GlslCompleter::isInComment(const QTextCursor &cursor) const
return CPlusPlus::MatchingText::isInCommentHelper(cursor);
}
QString GlslCompleter::insertMatchingBrace(const QTextCursor &cursor,
const QString &text,
QChar la,
int *skippedChars) const
QString GlslCompleter::insertMatchingBrace(const QTextCursor &cursor, const QString &text,
QChar lookAhead, int *skippedChars) const
{
return CPlusPlus::MatchingText::insertMatchingBrace(cursor, text, lookAhead, skippedChars);
}
QString GlslCompleter::insertMatchingQuote(const QTextCursor &cursor, const QString &text,
QChar lookAhead, int *skippedChars) const
{
return CPlusPlus::MatchingText::insertMatchingBrace(cursor, text, la, skippedChars);
return CPlusPlus::MatchingText::insertMatchingQuote(cursor, text, lookAhead, skippedChars);
}
QString GlslCompleter::insertParagraphSeparator(const QTextCursor &cursor) const
......
......@@ -33,15 +33,17 @@ namespace Internal {
class GlslCompleter : public TextEditor::AutoCompleter
{
public:
virtual bool contextAllowsAutoParentheses(const QTextCursor &cursor,
const QString &textToInsert = QString()) const;
virtual bool contextAllowsElectricCharacters(const QTextCursor &cursor) const;
virtual bool isInComment(const QTextCursor &cursor) const;
virtual QString insertMatchingBrace(const QTextCursor &cursor,
const QString &text,
QChar la,
int *skippedChars) const;
virtual QString insertParagraphSeparator(const QTextCursor &cursor) const;
bool contextAllowsAutoBrackets(const QTextCursor &cursor,
const QString &textToInsert = QString()) const override;
bool contextAllowsAutoQuotes(const QTextCursor &cursor,
const QString &textToInsert = QString()) const override;
bool contextAllowsElectricCharacters(const QTextCursor &cursor) const override;
bool isInComment(const QTextCursor &cursor) const override;
QString insertMatchingBrace(const QTextCursor &cursor, const QString &text,
QChar lookAhead, int *skippedChars) const override;
QString insertMatchingQuote(const QTextCursor &cursor, const QString &text,
QChar lookAhead, int *skippedChars) const override;
QString insertParagraphSeparator(const QTextCursor &cursor) const override;
};
} // namespace Internal
......
......@@ -139,8 +139,8 @@ AutoCompleter::AutoCompleter()
AutoCompleter::~AutoCompleter()
{}
bool AutoCompleter::contextAllowsAutoParentheses(const QTextCursor &cursor,
const QString &textToInsert) const
bool AutoCompleter::contextAllowsAutoBrackets(const QTextCursor &cursor,
const QString &textToInsert) const
{
QChar ch;
......@@ -148,9 +148,6 @@ bool AutoCompleter::contextAllowsAutoParentheses(const QTextCursor &cursor,
ch = textToInsert.at(0);
switch (ch.unicode()) {
case '\'':
case '"':
case '(':
case '[':
case '{':
......@@ -207,6 +204,50 @@ bool AutoCompleter::contextAllowsAutoParentheses(const QTextCursor &cursor,
return true;
}
bool AutoCompleter::contextAllowsAutoQuotes(const QTextCursor &cursor,
const QString &textToInsert) const
{
if (!isQuote(textToInsert))
return false;
const Token token = tokenUnderCursor(cursor);
switch (token.kind) {
case Token::Comment:
return false;
case Token::RightBrace:
return false;
case Token::String: {
const QString blockText = cursor.block().text();
const QStringRef tokenText = blockText.midRef(token.offset, token.length);
QChar quote = tokenText.at(0);
// if a string literal doesn't start with a quote, it must be multiline
if (quote != QLatin1Char('"') && quote != QLatin1Char('\'')) {
const int startState = blockStartState(cursor.block());
if ((startState & Scanner::MultiLineMask) == Scanner::MultiLineStringDQuote)
quote = QLatin1Char('"');
else if ((startState & Scanner::MultiLineMask) == Scanner::MultiLineStringSQuote)
quote = QLatin1Char('\'');
}
// never insert ' into string literals, it adds spurious ' when writing contractions
if (textToInsert.at(0) == QLatin1Char('\''))
return false;
if (textToInsert.at(0) != quote || isCompleteStringLiteral(tokenText))
break;
return false;
}
default:
break;
} // end of switch
return true;
}
bool AutoCompleter::contextAllowsElectricCharacters(const QTextCursor &cursor) const
{
Token token = tokenUnderCursor(cursor);
......@@ -226,7 +267,7 @@ bool AutoCompleter::isInComment(const QTextCursor &cursor) const
QString AutoCompleter::insertMatchingBrace(const QTextCursor &cursor,
const QString &text,
QChar la,
QChar lookAhead,
int *skippedChars) const
{
if (text.length() != 1)
......@@ -237,18 +278,6 @@ QString AutoCompleter::insertMatchingBrace(const QTextCursor &cursor,
const QChar ch = text.at(0);
switch (ch.unicode()) {
case '\'':
if (la != ch)
return QString(ch);
++*skippedChars;
break;
case '"':
if (la != ch)
return QString(ch);
++*skippedChars;
break;
case '(':
return QString(QLatin1Char(')'));
......@@ -262,7 +291,7 @@ QString AutoCompleter::insertMatchingBrace(const QTextCursor &cursor,
case ']':
case '}':
case ';':
if (la == ch)
if (lookAhead == ch)
++*skippedChars;
break;
......@@ -273,6 +302,17 @@ QString AutoCompleter::insertMatchingBrace(const QTextCursor &cursor,
return QString();
}
QString AutoCompleter::insertMatchingQuote(const QTextCursor &/*tc*/, const QString &text,
QChar lookAhead, int *skippedChars) const
{
if (isQuote(text)) {
if (lookAhead != text)
return text;
++*skippedChars;
}
return QString();
}
QString AutoCompleter::insertParagraphSeparator(const QTextCursor &cursor) const
{
if (shouldInsertNewline(cursor)) {
......
......@@ -34,17 +34,23 @@ class AutoCompleter : public TextEditor::AutoCompleter
{
public:
AutoCompleter();
virtual ~AutoCompleter();
~AutoCompleter() override;
virtual bool contextAllowsAutoParentheses(const QTextCursor &cursor,
const QString &textToInsert = QString()) const;
virtual bool contextAllowsElectricCharacters(const QTextCursor &cursor) const;
virtual bool isInComment(const QTextCursor &cursor) const;
virtual QString insertMatchingBrace(const QTextCursor &tc,
const QString &text,
QChar la,
int *skippedChars) const;
virtual QString insertParagraphSeparator(const QTextCursor &tc) const;
bool contextAllowsAutoBrackets(const QTextCursor &cursor,
const QString &textToInsert = QString()) const override;
bool contextAllowsAutoQuotes(const QTextCursor &cursor,
const QString &textToInsert = QString()) const override;
bool contextAllowsElectricCharacters(const QTextCursor &cursor) const override;
bool isInComment(const QTextCursor &cursor) const override;
QString insertMatchingBrace(const QTextCursor &tc,
const QString &text,
QChar lookAhead,
int *skippedChars) const override;
QString insertMatchingQuote(const QTextCursor &tc,
const QString &text,
QChar lookAhead,
int *skippedChars) const override;
QString insertParagraphSeparator(const QTextCursor &tc) const override;
};
} // Internal
......
......@@ -34,33 +34,15 @@ using namespace TextEditor;
AutoCompleter::AutoCompleter() :
m_allowSkippingOfBlockEnd(false),
m_surroundWithEnabled(true),
m_autoParenthesesEnabled(true)
m_autoInsertBrackets(true),
m_surroundWithBrackets(true),
m_autoInsertQuotes(true),
m_surroundWithQuotes(true)
{}
AutoCompleter::~AutoCompleter()
{}
void AutoCompleter::setAutoParenthesesEnabled(bool b)
{
m_autoParenthesesEnabled = b;
}
bool AutoCompleter::isAutoParenthesesEnabled() const
{
return m_autoParenthesesEnabled;
}
void AutoCompleter::setSurroundWithEnabled(bool b)
{
m_surroundWithEnabled = b;
}
bool AutoCompleter::isSurroundWithEnabled() const
{
return m_surroundWithEnabled;
}
static void countBracket(QChar open, QChar close, QChar c, int *errors, int *stillopen)
{
if (c == open)
......@@ -75,7 +57,7 @@ static void countBracket(QChar open, QChar close, QChar c, int *errors, int *sti
}
static void countBrackets(QTextCursor cursor, int from, int end, QChar open, QChar close,
int *errors, int *stillopen)
int *errors, int *stillopen)
{
cursor.setPosition(from);
QTextBlock block = cursor.block();
......@@ -124,11 +106,13 @@ static bool fixesBracketsError(const QString &textToInsert, const QTextCursor &c
return errorsAfterInsertion < errorsBeforeInsertion;
}
static QString replaceSelection(const QString &textToInsert, const QString &selection)
static QString surroundSelectionWithBrackets(const QString &textToInsert, const QString &selection)
{
QString replacement;
if (textToInsert == QLatin1String("(")) {
replacement = selection + QLatin1Char(')');
} else if (textToInsert == QLatin1String("[")) {
replacement = selection + QLatin1Char(']');
} else if (textToInsert == QLatin1String("{")) {
//If the text spans multiple lines, insert on different lines
replacement = selection;
......@@ -144,50 +128,62 @@ static QString replaceSelection(const QString &textToInsert, const QString &sele
} else {
replacement += QLatin1Char('}');
}
} else if (textToInsert == QLatin1String("[")) {
replacement = selection + QLatin1Char(']');
} else if (textToInsert == QLatin1String("\"")) {
replacement = selection + QLatin1Char('"');
} else if (textToInsert == QLatin1String("'")) {
replacement = selection + QLatin1Char('\'');
}
return replacement;
}
bool AutoCompleter::isQuote(const QString &text)
{
return text == QLatin1String("\"") || text == QLatin1String("'");
}
QString AutoCompleter::replaceSelection(QTextCursor &cursor, const QString &textToInsert) const
{
if (!cursor.hasSelection())
return QString();
if (isQuote(textToInsert) && m_surroundWithQuotes)
return cursor.selectedText() + textToInsert;
if (m_surroundWithBrackets)
return surroundSelectionWithBrackets(textToInsert, cursor.selectedText());
return QString();
}
QString AutoCompleter::autoComplete(QTextCursor &cursor, const QString &textToInsert) const
{