forked from qt-creator/qt-creator
Added CPPEditor::isInComment() and used it to remove the inserted quote characters.
CPPEditor::isInComment() returns if the text cursor is in a comment.
This commit is contained in:
@@ -1314,23 +1314,23 @@ bool CPPEditor::autoBackspace(QTextCursor &cursor)
|
|||||||
int pos = cursor.position();
|
int pos = cursor.position();
|
||||||
QTextCursor c = cursor;
|
QTextCursor c = cursor;
|
||||||
c.setPosition(pos - 1);
|
c.setPosition(pos - 1);
|
||||||
if (!contextAllowsAutoParentheses(c))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
QChar lookAhead = characterAt(pos);
|
QChar lookAhead = characterAt(pos);
|
||||||
QChar lookBehind = characterAt(pos-1);
|
QChar lookBehind = characterAt(pos-1);
|
||||||
QChar lookFurtherBehind = characterAt(pos-2);
|
QChar lookFurtherBehind = characterAt(pos-2);
|
||||||
if ((lookBehind == QLatin1Char('(') && lookAhead == QLatin1Char(')'))
|
if ((lookBehind == QLatin1Char('(') && lookAhead == QLatin1Char(')'))
|
||||||
|| (lookBehind == QLatin1Char('[') && lookAhead == QLatin1Char(']'))
|
|| (lookBehind == QLatin1Char('[') && lookAhead == QLatin1Char(']'))
|
||||||
|| (lookBehind == QLatin1Char('"') && lookAhead == QLatin1Char('"')
|
|| (lookBehind == QLatin1Char('"') && lookAhead == QLatin1Char('"')
|
||||||
&& lookFurtherBehind != QLatin1Char('\\'))
|
&& lookFurtherBehind != QLatin1Char('\\'))
|
||||||
|| (lookBehind == QLatin1Char('\'') && lookAhead == QLatin1Char('\'')
|
|| (lookBehind == QLatin1Char('\'') && lookAhead == QLatin1Char('\'')
|
||||||
&& lookFurtherBehind != QLatin1Char('\\'))) {
|
&& lookFurtherBehind != QLatin1Char('\\'))) {
|
||||||
cursor.beginEditBlock();
|
if (! isInComment(c)) {
|
||||||
cursor.deleteChar();
|
cursor.beginEditBlock();
|
||||||
cursor.deletePreviousChar();
|
cursor.deleteChar();
|
||||||
cursor.endEditBlock();
|
cursor.deletePreviousChar();
|
||||||
return true;
|
cursor.endEditBlock();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -1378,12 +1378,20 @@ bool CPPEditor::contextAllowsAutoParentheses(const QTextCursor &cursor,
|
|||||||
const QString &textToInsert) const
|
const QString &textToInsert) const
|
||||||
{
|
{
|
||||||
QChar ch;
|
QChar ch;
|
||||||
|
|
||||||
if (! textToInsert.isEmpty())
|
if (! textToInsert.isEmpty())
|
||||||
ch = textToInsert.at(0);
|
ch = textToInsert.at(0);
|
||||||
|
|
||||||
if (! (MatchingText::shouldInsertMatchingText(cursor) || ch == QLatin1Char('\'') || ch == QLatin1Char('"')))
|
if (! (MatchingText::shouldInsertMatchingText(cursor) || ch == QLatin1Char('\'') || ch == QLatin1Char('"')))
|
||||||
return false;
|
return false;
|
||||||
|
else if (isInComment(cursor))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CPPEditor::isInComment(const QTextCursor &cursor) const
|
||||||
|
{
|
||||||
CPlusPlus::TokenUnderCursor tokenUnderCursor;
|
CPlusPlus::TokenUnderCursor tokenUnderCursor;
|
||||||
const SimpleToken tk = tokenUnderCursor(cursor);
|
const SimpleToken tk = tokenUnderCursor(cursor);
|
||||||
|
|
||||||
@@ -1391,10 +1399,10 @@ bool CPPEditor::contextAllowsAutoParentheses(const QTextCursor &cursor,
|
|||||||
const int pos = cursor.selectionEnd();
|
const int pos = cursor.selectionEnd();
|
||||||
|
|
||||||
if (pos < tk.end())
|
if (pos < tk.end())
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CPPEditor::indentInsertedText(const QTextCursor &tc)
|
void CPPEditor::indentInsertedText(const QTextCursor &tc)
|
||||||
|
|||||||
@@ -220,6 +220,8 @@ protected:
|
|||||||
bool contextAllowsAutoParentheses(const QTextCursor &cursor,
|
bool contextAllowsAutoParentheses(const QTextCursor &cursor,
|
||||||
const QString &textToInsert = QString()) const;
|
const QString &textToInsert = QString()) const;
|
||||||
|
|
||||||
|
bool isInComment(const QTextCursor &cursor) const;
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
void updateFileName();
|
void updateFileName();
|
||||||
void jumpToMethod(int index);
|
void jumpToMethod(int index);
|
||||||
|
|||||||
Reference in New Issue
Block a user