aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/utils/textutils.cpp
diff options
context:
space:
mode:
authorDavid Schulz <[email protected]>2023-07-06 09:40:13 +0200
committerDavid Schulz <[email protected]>2023-07-07 07:57:26 +0000
commit5bf78e9955b8f2766713b977ef315e4a0a9c567b (patch)
treec367350e6da02bef9e718251d56946ba466c37e2 /src/libs/utils/textutils.cpp
parente75b81b0a898062e61c2231508cca06568d57665 (diff)
Utils: simplify Text::textAt
Change-Id: Ibada4af8b7bf76bb61fa45b00ac37bb8ed8a56b2 Reviewed-by: Christian Stenger <[email protected]>
Diffstat (limited to 'src/libs/utils/textutils.cpp')
-rw-r--r--src/libs/utils/textutils.cpp5
1 files changed, 2 insertions, 3 deletions
diff --git a/src/libs/utils/textutils.cpp b/src/libs/utils/textutils.cpp
index e486ca1b2b9..252152415f8 100644
--- a/src/libs/utils/textutils.cpp
+++ b/src/libs/utils/textutils.cpp
@@ -124,11 +124,10 @@ QString textAt(QTextCursor tc, int pos, int length)
if (pos < 0)
pos = 0;
tc.movePosition(QTextCursor::End);
- if (pos + length > tc.position())
- length = tc.position() - pos;
+ const int end = std::min(pos + length, tc.position());
tc.setPosition(pos);
- tc.setPosition(pos + length, QTextCursor::KeepAnchor);
+ tc.setPosition(end, QTextCursor::KeepAnchor);
// selectedText() returns U+2029 (PARAGRAPH SEPARATOR) instead of newline
return tc.selectedText().replace(QChar::ParagraphSeparator, QLatin1Char('\n'));