forked from qt-creator/qt-creator
Tweaks to skipping of closing parenthesis and quote characters
Done with mae.
This commit is contained in:
@@ -1074,11 +1074,13 @@ void BaseTextEditor::keyPressEvent(QKeyEvent *e)
|
|||||||
QString autoText;
|
QString autoText;
|
||||||
|
|
||||||
if (d->m_autoParenthesesEnabled && d->m_document->tabSettings().m_autoParentheses) {
|
if (d->m_autoParenthesesEnabled && d->m_document->tabSettings().m_autoParentheses) {
|
||||||
|
QChar lookAhead = characterAt(cursor.position());
|
||||||
foreach (QChar c, text) {
|
foreach (QChar c, text) {
|
||||||
QChar close;
|
QChar close;
|
||||||
if (c == QLatin1Char('('))
|
if (c == QLatin1Char('(')) {
|
||||||
close = QLatin1Char(')');
|
if (!lookAhead.isLetterOrNumber() && lookAhead != c)
|
||||||
else if (c == QLatin1Char('['))
|
close = QLatin1Char(')');
|
||||||
|
} else if (c == QLatin1Char('['))
|
||||||
close = QLatin1Char(']');
|
close = QLatin1Char(']');
|
||||||
else if (c == QLatin1Char('\"'))
|
else if (c == QLatin1Char('\"'))
|
||||||
close = c;
|
close = c;
|
||||||
@@ -1088,15 +1090,24 @@ void BaseTextEditor::keyPressEvent(QKeyEvent *e)
|
|||||||
autoText += close;
|
autoText += close;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool skip = false;
|
||||||
QChar first = text.at(0);
|
QChar first = text.at(0);
|
||||||
if (first == QLatin1Char(')')
|
if (first == QLatin1Char(')')) {
|
||||||
|| first == QLatin1Char(']')) {
|
skip = (first == lookAhead);
|
||||||
if (first == characterAt(cursor.position())) {
|
} else if (first == QLatin1Char(']')) {
|
||||||
int pos = cursor.position();
|
skip = (first == lookAhead);
|
||||||
cursor.setPosition(pos+1);
|
} else if (first == QLatin1Char('\"') || first == QLatin1Char('\'')) {
|
||||||
cursor.setPosition(pos, QTextCursor::KeepAnchor);
|
if (first == lookAhead) {
|
||||||
|
QChar lookBehind = characterAt(cursor.position()-1);
|
||||||
|
skip = (lookBehind != '\\');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (skip) {
|
||||||
|
int pos = cursor.position();
|
||||||
|
cursor.setPosition(pos+1);
|
||||||
|
cursor.setPosition(pos, QTextCursor::KeepAnchor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
QChar electricChar;
|
QChar electricChar;
|
||||||
if (d->m_document->tabSettings().m_autoIndent) {
|
if (d->m_document->tabSettings().m_autoIndent) {
|
||||||
|
|||||||
Reference in New Issue
Block a user