Commit c17edee6 authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer
Browse files

Only auto-insert when the text right of the cursor seems unrelated

To avoid bothering people who are trying to type an expression that is
already partly there.
parent 37d73f32
......@@ -1074,19 +1074,27 @@ void BaseTextEditor::keyPressEvent(QKeyEvent *e)
if (d->m_autoParenthesesEnabled && d->m_document->tabSettings().m_autoParentheses) {
QChar lookAhead = characterAt(cursor.position());
foreach (QChar c, text) {
QChar close;
if (c == QLatin1Char('(')) {
if (!lookAhead.isLetterOrNumber() && lookAhead != c)
if (lookAhead.isSpace() // Only auto-insert when the text right of the cursor seems unrelated
|| lookAhead == QLatin1Char('{')
|| lookAhead == QLatin1Char('}')
|| lookAhead == QLatin1Char(']')
|| lookAhead == QLatin1Char(')')
|| lookAhead == QLatin1Char(';')
|| lookAhead == QLatin1Char(',')
) {
foreach (QChar c, text) {
QChar close;
if (c == QLatin1Char('(')) {
close = QLatin1Char(')');
} else if (c == QLatin1Char('['))
close = QLatin1Char(']');
else if (c == QLatin1Char('\"'))
close = c;
else if (c == QLatin1Char('\''))
close = c;
if (!close.isNull())
autoText += close;
} else if (c == QLatin1Char('['))
close = QLatin1Char(']');
else if (c == QLatin1Char('\"'))
close = c;
else if (c == QLatin1Char('\''))
close = c;
if (!close.isNull())
autoText += close;
}
}
bool skip = false;
......
Markdown is supported
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