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

Merge branch '2.0'

Conflicts:
	src/plugins/cppeditor/cppquickfix.cpp
	src/plugins/mercurial/mercurialjobrunner.cpp
	src/plugins/subversion/subversionplugin.cpp
parents 4f458551 83dba068
......@@ -109,7 +109,7 @@ QString MatchingText::insertMatchingBrace(const QTextCursor &cursor, const QStri
QTextDocument *doc = tc.document();
QString text = textToProcess;
const QString blockText = tc.block().text().mid(tc.columnNumber());
const QString blockText = tc.block().text().mid(tc.positionInBlock());
const int length = qMin(blockText.length(), textToProcess.length());
const QChar previousChar = doc->characterAt(tc.selectionEnd() - 1);
......@@ -219,7 +219,7 @@ QString MatchingText::insertParagraphSeparator(const QTextCursor &tc) const
if (tk[index - 1].isNot(T_LBRACE))
return QString(); // nothing to do.
const QString textBlock = tc.block().text().mid(tc.columnNumber()).trimmed();
const QString textBlock = tc.block().text().mid(tc.positionInBlock()).trimmed();
if (! textBlock.isEmpty())
return QString();
......
......@@ -1421,6 +1421,37 @@ bool CPPEditor::contextAllowsAutoParentheses(const QTextCursor &cursor,
return true;
}
bool CPPEditor::contextAllowsElectricCharacters(const QTextCursor &cursor) const
{
const SimpleToken tk = tokenCache()->tokenUnderCursor(cursor);
// XXX Duplicated from CPPEditor::isInComment to avoid tokenizing twice
if (tk.isComment()) {
const int pos = cursor.selectionEnd() - cursor.block().position();
if (pos == tk.end()) {
if (tk.is(T_CPP_COMMENT) || tk.is(T_CPP_DOXY_COMMENT))
return false;
const int state = cursor.block().userState() & 0xFF;
if (state > 0)
return false;
}
if (pos < tk.end())
return false;
}
else if (tk.is(T_STRING_LITERAL) || tk.is(T_WIDE_STRING_LITERAL)
|| tk.is(T_CHAR_LITERAL) || tk.is(T_WIDE_CHAR_LITERAL)) {
const int pos = cursor.selectionEnd() - cursor.block().position();
if (pos <= tk.end())
return false;
}
return true;
}
bool CPPEditor::isInComment(const QTextCursor &cursor) const
{
const SimpleToken tk = tokenCache()->tokenUnderCursor(cursor);
......@@ -1557,7 +1588,7 @@ void CPPEditor::contextMenuEvent(QContextMenuEvent *e)
// ### enable
// updateSemanticInfo(m_semanticHighlighter->semanticInfo(currentSource()));
QMenu *menu = new QMenu();
QMenu *menu = new QMenu;
Core::ActionManager *am = Core::ICore::instance()->actionManager();
Core::ActionContainer *mcontext = am->actionContainer(CppEditor::Constants::M_CONTEXT);
......
......@@ -231,6 +231,7 @@ protected:
virtual bool contextAllowsAutoParentheses(const QTextCursor &cursor,
const QString &textToInsert = QString()) const;
virtual bool contextAllowsElectricCharacters(const QTextCursor &cursor) const;
virtual bool isInComment(const QTextCursor &cursor) const;
......
......@@ -748,11 +748,11 @@ QString cppExpressionAt(TextEditor::ITextEditor *editor, int pos,
// Fetch the expression's code.
CPlusPlus::ExpressionUnderCursor expressionUnderCursor(modelManager->tokenCache(editor));
expr = expressionUnderCursor(tc);
*column = tc.columnNumber();
*column = tc.positionInBlock();
*line = tc.blockNumber();
} else {
const QTextCursor tc = plaintext->textCursor();
*column = tc.columnNumber();
*column = tc.positionInBlock();
*line = tc.blockNumber();
}
......
......@@ -1464,8 +1464,8 @@ void FakeVimHandler::Private::updateSelection()
} else if (isVisualBlockMode()) {
QTextCursor tc = m_tc;
tc.setPosition(anchorPos);
int anchorColumn = tc.columnNumber();
int cursorColumn = m_tc.columnNumber();
int anchorColumn = tc.positionInBlock();
int cursorColumn = m_tc.positionInBlock();
int anchorRow = tc.blockNumber();
int cursorRow = m_tc.blockNumber();
int startColumn = qMin(anchorColumn, cursorColumn);
......
......@@ -283,7 +283,7 @@ bool ExpressionQueryWidget::eventFilter(QObject *obj, QEvent *event)
bool atLastLine = !(cursor.block().next().isValid());
if (!atLastLine)
return true;
if (cursor.columnNumber() <= m_prompt.count())
if (cursor.positionInBlock() <= m_prompt.count())
return true;
cursor.deletePreviousChar();
m_expr = cursor.block().text().mid(m_prompt.count());
......
......@@ -102,7 +102,7 @@ public:
_cursor = cursor;
QTextBlock block = _cursor.block();
const QString blockText = block.text().left(cursor.columnNumber());
const QString blockText = block.text().left(cursor.positionInBlock());
scanner.setScanComments(false);
const QList<Token> tokens = scanner(blockText, startState(block));
......
......@@ -523,7 +523,7 @@ bool CodeCompletion::triggersCompletion(TextEditor::ITextEditable *editor)
QTextCursor tc = ed->textCursor();
QTextBlock block = tc.block();
const int column = tc.columnNumber();
const int column = tc.positionInBlock();
const int blockState = qMax(0, block.previous().userState()) & 0xff;
const QString blockText = block.text();
......
......@@ -1103,6 +1103,34 @@ static bool isCompleteStringLiteral(const QStringRef &text)
return false;
}
static Token tokenUnderCursor(const QTextCursor &cursor)
{
const QString blockText = cursor.block().text();
const int blockState = blockStartState(cursor.block());
Scanner tokenize;
const QList<Token> tokens = tokenize(blockText, blockState);
const int pos = cursor.positionInBlock();
int tokenIndex = 0;
for (; tokenIndex < tokens.size(); ++tokenIndex) {
const Token &token = tokens.at(tokenIndex);
if (token.is(Token::Comment) || token.is(Token::String)) {
if (pos > token.begin() && pos <= token.end())
break;
} else {
if (pos >= token.begin() && pos < token.end())
break;
}
}
if (tokenIndex != tokens.size())
return tokens.at(tokenIndex);
return Token();
}
bool QmlJSTextEditor::contextAllowsAutoParentheses(const QTextCursor &cursor, const QString &textToInsert) const
{
QChar ch;
......@@ -1132,56 +1160,45 @@ bool QmlJSTextEditor::contextAllowsAutoParentheses(const QTextCursor &cursor, co
return false;
} // end of switch
const QString blockText = cursor.block().text();
const int blockState = blockStartState(cursor.block());
const Token token = tokenUnderCursor(cursor);
switch (token.kind) {
case Token::Comment:
return false;
Scanner tokenize;
const QList<Token> tokens = tokenize(blockText, blockState);
const int pos = cursor.columnNumber();
case Token::String: {
const QString blockText = cursor.block().text();
const QStringRef tokenText = blockText.midRef(token.offset, token.length);
const QChar quote = tokenText.at(0);
int tokenIndex = 0;
for (; tokenIndex < tokens.size(); ++tokenIndex) {
const Token &token = tokens.at(tokenIndex);
if (pos >= token.begin()) {
if (pos < token.end())
break;
if (ch != quote || isCompleteStringLiteral(tokenText))
break;
else if (pos == token.end() && (token.is(Token::Comment) ||
token.is(Token::String)))
break;
}
return false;
}
if (tokenIndex != tokens.size()) {
const Token &token = tokens.at(tokenIndex);
switch (token.kind) {
case Token::Comment:
return false;
case Token::String: {
const QStringRef tokenText = blockText.midRef(token.offset, token.length);
const QChar quote = tokenText.at(0);
if (ch != quote || isCompleteStringLiteral(tokenText))
break;
default:
break;
} // end of switch
return false;
}
return true;
}
default:
break;
} // end of switch
bool QmlJSTextEditor::contextAllowsElectricCharacters(const QTextCursor &cursor) const
{
Token token = tokenUnderCursor(cursor);
qDebug() << cursor.positionInBlock() << token.begin() << token.end();
switch (token.kind) {
case Token::Comment:
case Token::String:
return false;
default:
return true;
}
return true;
}
bool QmlJSTextEditor::isInComment(const QTextCursor &) const
bool QmlJSTextEditor::isInComment(const QTextCursor &cursor) const
{
// ### implement me
return false;
return tokenUnderCursor(cursor).is(Token::Comment);
}
QString QmlJSTextEditor::insertMatchingBrace(const QTextCursor &tc, const QString &text, QChar, int *skippedChars) const
......
......@@ -248,6 +248,7 @@ protected:
//// brace matching
virtual bool contextAllowsAutoParentheses(const QTextCursor &cursor, const QString &textToInsert = QString()) const;
virtual bool contextAllowsElectricCharacters(const QTextCursor &cursor) const;
virtual bool isInComment(const QTextCursor &cursor) const;
virtual QString insertMatchingBrace(const QTextCursor &tc, const QString &text, QChar la, int *skippedChars) const;
virtual QString insertParagraphSeparator(const QTextCursor &tc) const;
......
......@@ -1351,7 +1351,7 @@ void BaseTextEditor::keyPressEvent(QKeyEvent *e)
cursor.insertText(autoText);
cursor.setPosition(pos);
}
if (!electricChar.isNull())
if (!electricChar.isNull() && contextAllowsElectricCharacters(cursor))
indent(document(), cursor, electricChar);
if (doEditBlock)
......@@ -3824,6 +3824,11 @@ bool BaseTextEditor::contextAllowsAutoParentheses(const QTextCursor &cursor,
return false;
}
bool BaseTextEditor::contextAllowsElectricCharacters(const QTextCursor &cursor) const
{
return contextAllowsAutoParentheses(cursor);
}
bool BaseTextEditor::isInComment(const QTextCursor &cursor) const
{
Q_UNUSED(cursor);
......
......@@ -407,6 +407,7 @@ public:
virtual void reindent(QTextDocument *doc, const QTextCursor &cursor);
virtual bool contextAllowsAutoParentheses(const QTextCursor &cursor, const QString &textToInsert = QString()) const;
virtual bool contextAllowsElectricCharacters(const QTextCursor &cursor) const;
// Returns true if the cursor is inside a comment.
virtual bool isInComment(const QTextCursor &cursor) const;
......
......@@ -192,7 +192,7 @@ bool TabSettings::tabShouldIndent(const QTextDocument *document, QTextCursor cur
return true;
if (document->characterAt(tc.position()).isSpace()) {
tc.movePosition(QTextCursor::WordRight);
if (tc.columnNumber() >= cursor.columnNumber()) {
if (tc.positionInBlock() >= cursor.positionInBlock()) {
if (suggestedPosition)
*suggestedPosition = tc.position(); // Suggest position after whitespace
if (m_tabKeyBehavior == TabLeadingWhitespaceIndents)
......
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