Commit e790363f authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Check the lookahead character before inserting the matching quote or brace.

parent d3ed242d
......@@ -98,6 +98,30 @@ int blockStartState(const QTextBlock &block)
else
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
namespace QmlJSEditor {
......@@ -825,6 +849,9 @@ QString QmlJSTextEditor::insertMatchingBrace(const QTextCursor &tc, const QStrin
if (text.length() != 1)
return QString();
if (! shouldInsertMatchingText(tc))
return QString();
const QChar la = characterAt(tc.position());
const QChar ch = text.at(0);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment