mirror of
https://github.com/RGBCube/serenity
synced 2025-05-16 19:45:07 +00:00
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.
This commit is contained in:
parent
c1efa4f336
commit
bddba567b3
3 changed files with 21 additions and 12 deletions
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue