@@ -417,23 +417,6 @@ bool HTMLSelectElement::has_activation_behavior() const
417
417
return true ;
418
418
}
419
419
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
-
437
420
// https://html.spec.whatwg.org/multipage/input.html#show-the-picker,-if-applicable
438
421
void HTMLSelectElement::show_the_picker_if_applicable ()
439
422
{
@@ -478,7 +461,7 @@ void HTMLSelectElement::show_the_picker_if_applicable()
478
461
for (auto const & child : opt_group_element->children_as_vector ()) {
479
462
if (auto const & option_element = as_if<HTMLOptionElement>(*child)) {
480
463
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 () });
482
465
}
483
466
}
484
467
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()
487
470
488
471
if (auto const & option_element = as_if<HTMLOptionElement>(*child)) {
489
472
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 () });
491
474
}
492
475
493
476
if (auto const * hr_element = as_if<HTMLHRElement>(*child)) {
@@ -649,7 +632,7 @@ void HTMLSelectElement::update_inner_text_element()
649
632
// Update inner text element to the label of the selected option
650
633
for (auto const & option_element : m_cached_list_of_options) {
651
634
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 () )));
653
636
return ;
654
637
}
655
638
}
0 commit comments