forked from qt-creator/qt-creator
Utils: pass a document instead of a cursor to Utils::Text::textAt
None of the additional information by the cursor was used and almost all usages of the function created a text cursor for calling this function. Change-Id: I2667103738d159b33b7769d1934c435e45bd1bdd Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -156,10 +156,11 @@ int positionInText(const QTextDocument *textDocument, int line, int column)
|
||||
return textDocument->findBlockByNumber(line - 1).position() + column - 1;
|
||||
}
|
||||
|
||||
QString textAt(QTextCursor tc, int pos, int length)
|
||||
QString textAt(QTextDocument *textDocument, int pos, int length)
|
||||
{
|
||||
if (pos < 0)
|
||||
pos = 0;
|
||||
QTextCursor tc(textDocument);
|
||||
tc.movePosition(QTextCursor::End);
|
||||
const int end = std::min(pos + length, tc.position());
|
||||
|
||||
|
@@ -65,7 +65,7 @@ QTCREATOR_UTILS_EXPORT bool convertPosition(const QTextDocument *document,
|
||||
// line and column are 1-based
|
||||
QTCREATOR_UTILS_EXPORT int positionInText(const QTextDocument *textDocument, int line, int column);
|
||||
|
||||
QTCREATOR_UTILS_EXPORT QString textAt(QTextCursor tc, int pos, int length);
|
||||
QTCREATOR_UTILS_EXPORT QString textAt(QTextDocument *textDocument, int pos, int length);
|
||||
|
||||
// line is 1-based, column is 0-based
|
||||
QTCREATOR_UTILS_EXPORT QTextCursor selectAt(QTextCursor textCursor, int line, int column, uint length);
|
||||
|
@@ -73,8 +73,7 @@ void ActivationSequenceContextProcessor::process()
|
||||
void ActivationSequenceContextProcessor::processActivationSequence()
|
||||
{
|
||||
const int nonSpacePosition = skipPrecedingWhitespace(m_document, m_startOfNamePosition);
|
||||
const auto activationSequence = Utils::Text::textAt(QTextCursor(m_document),
|
||||
nonSpacePosition - 3, 3);
|
||||
const auto activationSequence = Utils::Text::textAt(m_document, nonSpacePosition - 3, 3);
|
||||
ActivationSequenceProcessor activationSequenceProcessor(activationSequence,
|
||||
nonSpacePosition,
|
||||
true);
|
||||
|
@@ -464,11 +464,10 @@ static ChangeSet convertReplacements(const QTextDocument *doc,
|
||||
|
||||
static QString selectedLines(QTextDocument *doc, const QTextBlock &startBlock, const QTextBlock &endBlock)
|
||||
{
|
||||
return Text::textAt(QTextCursor(doc),
|
||||
startBlock.position(),
|
||||
std::max(0,
|
||||
endBlock.position() + endBlock.length()
|
||||
- startBlock.position() - 1));
|
||||
return Text::textAt(
|
||||
doc,
|
||||
startBlock.position(),
|
||||
std::max(0, endBlock.position() + endBlock.length() - startBlock.position() - 1));
|
||||
}
|
||||
|
||||
static int indentationForBlock(const ChangeSet &toReplace,
|
||||
|
@@ -118,7 +118,7 @@ public:
|
||||
|
||||
const int pos = proposal->basePosition();
|
||||
const int length = m_position - pos;
|
||||
const QString prefix = Utils::Text::textAt(QTextCursor(m_textDocument), pos, length);
|
||||
const QString prefix = Utils::Text::textAt(m_textDocument, pos, length);
|
||||
if (!prefix.isEmpty())
|
||||
listmodel->filter(prefix);
|
||||
if (listmodel->isSortable(prefix))
|
||||
|
@@ -204,12 +204,12 @@ bool LanguageClientCompletionItem::isPerfectMatch(int pos, QTextDocument *doc) c
|
||||
auto range = edit->range();
|
||||
const int start = positionInText(doc, range.start().line() + 1, range.start().character() + 1);
|
||||
const int end = positionInText(doc, range.end().line() + 1, range.end().character() + 1);
|
||||
auto text = textAt(QTextCursor(doc), start, end - start);
|
||||
auto text = textAt(doc, start, end - start);
|
||||
return text == edit->newText();
|
||||
}
|
||||
const QString textToInsert(m_item.insertText().value_or(text()));
|
||||
const int length = textToInsert.length();
|
||||
return textToInsert == textAt(QTextCursor(doc), pos - length, length);
|
||||
return textToInsert == textAt(doc, pos - length, length);
|
||||
}
|
||||
|
||||
bool LanguageClientCompletionItem::isDeprecated() const
|
||||
|
@@ -104,7 +104,7 @@ QChar AssistInterface::characterAt(int position) const
|
||||
|
||||
QString AssistInterface::textAt(int pos, int length) const
|
||||
{
|
||||
return Utils::Text::textAt(QTextCursor(m_textDocument), pos, length);
|
||||
return Utils::Text::textAt(m_textDocument, pos, length);
|
||||
}
|
||||
|
||||
void AssistInterface::prepareForAsyncUse()
|
||||
|
@@ -50,7 +50,7 @@ static QString sourceData(TextEditorWidget *editor, int startPos, int endPos)
|
||||
{
|
||||
return (startPos < 0)
|
||||
? editor->toPlainText()
|
||||
: Utils::Text::textAt(editor->textCursor(), startPos, (endPos - startPos));
|
||||
: Utils::Text::textAt(editor->document(), startPos, (endPos - startPos));
|
||||
}
|
||||
|
||||
static FormatOutput format(const FormatInput &input)
|
||||
|
@@ -334,7 +334,7 @@ QString TextDocument::plainText() const
|
||||
|
||||
QString TextDocument::textAt(int pos, int length) const
|
||||
{
|
||||
return Utils::Text::textAt(QTextCursor(document()), pos, length);
|
||||
return Utils::Text::textAt(document(), pos, length);
|
||||
}
|
||||
|
||||
QChar TextDocument::characterAt(int pos) const
|
||||
|
Reference in New Issue
Block a user