forked from qt-creator/qt-creator
Lua: move toTextCursor helper to Text::Position
Change-Id: Ie3b07d8eef3f68cdd526236b771c3fec4d5d3bda Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -26,6 +26,13 @@ int Position::positionInDocument(QTextDocument *doc) const
|
||||
return block.position() + column;
|
||||
}
|
||||
|
||||
QTextCursor Position::toTextCursor(QTextDocument *doc) const
|
||||
{
|
||||
QTextCursor result(doc);
|
||||
result.setPosition(positionInDocument(doc));
|
||||
return result;
|
||||
}
|
||||
|
||||
/*!
|
||||
Returns the text position of a \a fileName and sets the \a postfixPos if
|
||||
it can find a positional postfix.
|
||||
|
@@ -31,6 +31,7 @@ public:
|
||||
bool isValid() const { return line > 0 && column >= 0; }
|
||||
|
||||
int positionInDocument(QTextDocument *doc) const;
|
||||
QTextCursor toTextCursor(QTextDocument *doc) const;
|
||||
|
||||
static Position fromFileName(QStringView fileName, int &postfixPos);
|
||||
static Position fromPositionInDocument(const QTextDocument *document, int pos);
|
||||
|
@@ -39,13 +39,6 @@ private:
|
||||
QString m_text;
|
||||
};
|
||||
|
||||
QTextCursor toTextCursor(QTextDocument *doc, const Text::Position &position)
|
||||
{
|
||||
QTextCursor cursor(doc);
|
||||
cursor.setPosition(position.toPositionInDocument(doc));
|
||||
return cursor;
|
||||
}
|
||||
|
||||
class CyclicSuggestion : public QObject, public TextEditor::TextSuggestion
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -66,7 +59,7 @@ public:
|
||||
const auto start = suggestion.range().begin;
|
||||
const auto end = suggestion.range().end;
|
||||
|
||||
QString text = toTextCursor(origin_document->document(), start).block().text();
|
||||
QString text = start.toTextCursor(origin_document->document()).block().text();
|
||||
int length = text.length() - start.column;
|
||||
if (start.line == end.line)
|
||||
length = end.column - start.column;
|
||||
@@ -74,7 +67,7 @@ public:
|
||||
text.replace(start.column, length, suggestion.text());
|
||||
document()->setPlainText(text);
|
||||
|
||||
m_start = toTextCursor(origin_document->document(), suggestion.position());
|
||||
m_start = suggestion.position().toTextCursor(origin_document->document());
|
||||
m_start.setKeepPositionOnInsert(true);
|
||||
setCurrentPosition(m_start.position());
|
||||
|
||||
|
Reference in New Issue
Block a user