forked from qt-creator/qt-creator
Check the lookahead character before inserting the matching quote or brace.
This commit is contained in:
@@ -98,6 +98,30 @@ int blockStartState(const QTextBlock &block)
|
|||||||
else
|
else
|
||||||
return state & 0xff;
|
return state & 0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool shouldInsertMatchingText(const QChar &lookAhead)
|
||||||
|
{
|
||||||
|
switch (lookAhead.unicode()) {
|
||||||
|
case '{': case '}':
|
||||||
|
case ']': case ')':
|
||||||
|
case ';': case ',':
|
||||||
|
case '"': case '\'':
|
||||||
|
return true;
|
||||||
|
|
||||||
|
default:
|
||||||
|
if (lookAhead.isSpace())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
} // switch
|
||||||
|
}
|
||||||
|
|
||||||
|
bool shouldInsertMatchingText(const QTextCursor &tc)
|
||||||
|
{
|
||||||
|
QTextDocument *doc = tc.document();
|
||||||
|
return shouldInsertMatchingText(doc->characterAt(tc.selectionEnd()));
|
||||||
|
}
|
||||||
|
|
||||||
} // end of anonymous namespace
|
} // end of anonymous namespace
|
||||||
|
|
||||||
namespace QmlJSEditor {
|
namespace QmlJSEditor {
|
||||||
@@ -825,6 +849,9 @@ QString QmlJSTextEditor::insertMatchingBrace(const QTextCursor &tc, const QStrin
|
|||||||
if (text.length() != 1)
|
if (text.length() != 1)
|
||||||
return QString();
|
return QString();
|
||||||
|
|
||||||
|
if (! shouldInsertMatchingText(tc))
|
||||||
|
return QString();
|
||||||
|
|
||||||
const QChar la = characterAt(tc.position());
|
const QChar la = characterAt(tc.position());
|
||||||
|
|
||||||
const QChar ch = text.at(0);
|
const QChar ch = text.at(0);
|
||||||
|
|||||||
Reference in New Issue
Block a user