Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
...@@ -98,6 +98,30 @@ int blockStartState(const QTextBlock &block) ...@@ -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 ...@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment