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

Added CPPEditor::isInComment() and used it to remove the inserted quote characters.

CPPEditor::isInComment() returns if the text cursor is in a comment.
parent 6b504c61
...@@ -1314,23 +1314,23 @@ bool CPPEditor::autoBackspace(QTextCursor &cursor) ...@@ -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, ...@@ -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, ...@@ -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: ...@@ -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);
......
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