Skip to content

Commit 63bce2b

Browse files
trflynn89gmta
authored andcommitted
LibWeb: Remove the ad-hoc strip_newlines method from HTMLSelectElement
This doesn't appear to be doing anything that the Infra method it calls isn't already doing.
1 parent d950250 commit 63bce2b

File tree

1 file changed

+3
-20
lines changed

1 file changed

+3
-20
lines changed

Libraries/LibWeb/HTML/HTMLSelectElement.cpp

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -417,23 +417,6 @@ bool HTMLSelectElement::has_activation_behavior() const
417417
return true;
418418
}
419419

420-
static String strip_newlines(Optional<String> string)
421-
{
422-
// FIXME: Move this to a more general function
423-
if (!string.has_value())
424-
return {};
425-
426-
StringBuilder builder;
427-
for (auto c : string.value().bytes_as_string_view()) {
428-
if (c == '\r' || c == '\n') {
429-
builder.append(' ');
430-
} else {
431-
builder.append(c);
432-
}
433-
}
434-
return MUST(Infra::strip_and_collapse_whitespace(MUST(builder.to_string())));
435-
}
436-
437420
// https://html.spec.whatwg.org/multipage/input.html#show-the-picker,-if-applicable
438421
void HTMLSelectElement::show_the_picker_if_applicable()
439422
{
@@ -478,7 +461,7 @@ void HTMLSelectElement::show_the_picker_if_applicable()
478461
for (auto const& child : opt_group_element->children_as_vector()) {
479462
if (auto const& option_element = as_if<HTMLOptionElement>(*child)) {
480463
if (!option_element->has_attribute(Web::HTML::AttributeNames::hidden))
481-
option_group_items.append(SelectItemOption { id_counter++, option_element->selected(), option_element->disabled(), option_element, strip_newlines(option_element->label()), option_element->value().to_utf8_but_should_be_ported_to_utf16() });
464+
option_group_items.append(SelectItemOption { id_counter++, option_element->selected(), option_element->disabled(), option_element, MUST(Infra::strip_and_collapse_whitespace(option_element->label())), option_element->value().to_utf8_but_should_be_ported_to_utf16() });
482465
}
483466
}
484467
m_select_items.append(SelectItemOptionGroup { opt_group_element->get_attribute(AttributeNames::label).value_or(String {}), option_group_items });
@@ -487,7 +470,7 @@ void HTMLSelectElement::show_the_picker_if_applicable()
487470

488471
if (auto const& option_element = as_if<HTMLOptionElement>(*child)) {
489472
if (!option_element->has_attribute(Web::HTML::AttributeNames::hidden))
490-
m_select_items.append(SelectItemOption { id_counter++, option_element->selected(), option_element->disabled(), option_element, strip_newlines(option_element->label()), option_element->value().to_utf8_but_should_be_ported_to_utf16() });
473+
m_select_items.append(SelectItemOption { id_counter++, option_element->selected(), option_element->disabled(), option_element, MUST(Infra::strip_and_collapse_whitespace(option_element->label())), option_element->value().to_utf8_but_should_be_ported_to_utf16() });
491474
}
492475

493476
if (auto const* hr_element = as_if<HTMLHRElement>(*child)) {
@@ -649,7 +632,7 @@ void HTMLSelectElement::update_inner_text_element()
649632
// Update inner text element to the label of the selected option
650633
for (auto const& option_element : m_cached_list_of_options) {
651634
if (option_element->selected()) {
652-
m_inner_text_element->set_text_content(strip_newlines(option_element->label()));
635+
m_inner_text_element->set_text_content(MUST(Infra::strip_and_collapse_whitespace(option_element->label())));
653636
return;
654637
}
655638
}

0 commit comments

Comments
 (0)