LibGUI: Use normalized TextRange for early empty string check

Fixes #6141. Allows to copy "backward" selections.
This commit is contained in:
Maciej Zygmanowski 2021-04-05 15:34:39 +02:00 committed by Andreas Kling
parent 1f65c2a981
commit 8646f8f4ad
Notes: sideshowbarker 2024-07-18 20:45:51 +09:00

View file

@ -343,9 +343,9 @@ String TextDocument::text() const
String TextDocument::text_in_range(const TextRange& a_range) const
{
if (is_empty() || line_count() < a_range.end().line() - a_range.start().line() || line(a_range.start().line()).is_empty())
return String("");
auto range = a_range.normalized();
if (is_empty() || line_count() < range.end().line() - range.start().line() || line(range.start().line()).is_empty())
return String("");
StringBuilder builder;
for (size_t i = range.start().line(); i <= range.end().line(); ++i) {