summaryrefslogtreecommitdiff
path: root/Libraries/LibGUI/GTextEditor.cpp
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-10-29 21:36:47 +0100
committerAndreas Kling <awesomekling@gmail.com>2019-10-30 20:28:44 +0100
commitbddba567b3df3e7ee22174cc3ea5d0425a492469 (patch)
tree0553bb962d2742fed12aed4286730dec28b324b4 /Libraries/LibGUI/GTextEditor.cpp
parentc1efa4f3360afc4e20254238b284b66ef8a361b0 (diff)
downloadserenity-bddba567b3df3e7ee22174cc3ea5d0425a492469.zip
LibGUI: Add GTextDocument::text_in_range(GTextRange)
This function returns a String containing the text in a given range. GTextEditor::selected_text() is now just a wrapper around this.
Diffstat (limited to 'Libraries/LibGUI/GTextEditor.cpp')
-rw-r--r--Libraries/LibGUI/GTextEditor.cpp13
1 files changed, 1 insertions, 12 deletions
diff --git a/Libraries/LibGUI/GTextEditor.cpp b/Libraries/LibGUI/GTextEditor.cpp
index 9b991eaff6..148c60f584 100644
--- a/Libraries/LibGUI/GTextEditor.cpp
+++ b/Libraries/LibGUI/GTextEditor.cpp
@@ -1002,18 +1002,7 @@ String GTextEditor::selected_text() const
if (!has_selection())
return {};
- auto selection = normalized_selection();
- StringBuilder builder;
- for (int i = selection.start().line(); i <= selection.end().line(); ++i) {
- auto& line = lines()[i];
- int selection_start_column_on_line = selection.start().line() == i ? selection.start().column() : 0;
- int selection_end_column_on_line = selection.end().line() == i ? selection.end().column() : line.length();
- builder.append(line.characters() + selection_start_column_on_line, selection_end_column_on_line - selection_start_column_on_line);
- if (i != selection.end().line())
- builder.append('\n');
- }
-
- return builder.to_string();
+ return document().text_in_range(m_selection);
}
void GTextEditor::delete_selection()