TextEditor: Introduce some convenience text accessors in the editor

And adjust users.

Change-Id: I9329257cfa5f3298731deb07c2881bc37d9a051d
Reviewed-by: Christian Stenger <christian.stenger@digia.com>
This commit is contained in:
hjk
2014-08-27 11:57:32 +02:00
parent d2c243464e
commit 2a5c602341
19 changed files with 111 additions and 104 deletions

View File

@@ -456,7 +456,7 @@ void ClangAssistProposalItem::applyContextualContent(TextEditor::BaseTextEditor
// If the function doesn't return anything, automatically place the semicolon,
// unless we're doing a scope completion (then it might be function definition).
const QChar characterAtCursor = editor->textDocument()->characterAt(editor->position());
const QChar characterAtCursor = editor->characterAt(editor->position());
bool endWithSemicolon = m_typedChar == QLatin1Char(';')/*
|| (function->returnType()->isVoidType() && m_completionOperator != T_COLON_COLON)*/; //###
const QChar semicolon = m_typedChar.isNull() ? QLatin1Char(';') : m_typedChar;
@@ -474,7 +474,7 @@ void ClangAssistProposalItem::applyContextualContent(TextEditor::BaseTextEditor
m_typedChar = QChar();
}
} else if (autoParenthesesEnabled) {
const QChar lookAhead = editor->textDocument()->characterAt(editor->position() + 1);
const QChar lookAhead = editor->characterAt(editor->position() + 1);
if (MatchingText::shouldInsertMatchingText(lookAhead)) {
extraChars += QLatin1Char(')');
--cursorOffset;
@@ -510,8 +510,7 @@ void ClangAssistProposalItem::applyContextualContent(TextEditor::BaseTextEditor
// Avoid inserting characters that are already there
const int endsPosition = editor->position(TextEditor::BaseTextEditor::EndOfLine);
const QString existingText = editor->textDocument()->textAt(editor->position(),
endsPosition - editor->position());
const QString existingText = editor->textAt(editor->position(), endsPosition - editor->position());
int existLength = 0;
if (!existingText.isEmpty()) {
// Calculate the exist length in front of the extra chars
@@ -523,7 +522,7 @@ void ClangAssistProposalItem::applyContextualContent(TextEditor::BaseTextEditor
}
for (int i = 0; i < extraChars.length(); ++i) {
const QChar a = extraChars.at(i);
const QChar b = editor->textDocument()->characterAt(editor->position() + i + existLength);
const QChar b = editor->characterAt(editor->position() + i + existLength);
if (a == b)
++extraLength;
else