forked from qt-creator/qt-creator
Utils: simplify Text::textAt
Change-Id: Ibada4af8b7bf76bb61fa45b00ac37bb8ed8a56b2 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -124,11 +124,10 @@ QString textAt(QTextCursor tc, int pos, int length)
|
|||||||
if (pos < 0)
|
if (pos < 0)
|
||||||
pos = 0;
|
pos = 0;
|
||||||
tc.movePosition(QTextCursor::End);
|
tc.movePosition(QTextCursor::End);
|
||||||
if (pos + length > tc.position())
|
const int end = std::min(pos + length, tc.position());
|
||||||
length = tc.position() - pos;
|
|
||||||
|
|
||||||
tc.setPosition(pos);
|
tc.setPosition(pos);
|
||||||
tc.setPosition(pos + length, QTextCursor::KeepAnchor);
|
tc.setPosition(end, QTextCursor::KeepAnchor);
|
||||||
|
|
||||||
// selectedText() returns U+2029 (PARAGRAPH SEPARATOR) instead of newline
|
// selectedText() returns U+2029 (PARAGRAPH SEPARATOR) instead of newline
|
||||||
return tc.selectedText().replace(QChar::ParagraphSeparator, QLatin1Char('\n'));
|
return tc.selectedText().replace(QChar::ParagraphSeparator, QLatin1Char('\n'));
|
||||||
|
|||||||
Reference in New Issue
Block a user