LibGUI: Don't allow 4 character html color codes in GUI::ColorPicker

When 4 character colors were allowed, backspace misbehaved and you
couldn't backspace the whole color.
This commit is contained in:
Peter Elliott 2020-09-16 17:28:34 -07:00 committed by Andreas Kling
parent d89cad7c57
commit 9670d9ad50
Notes: sideshowbarker 2024-07-19 02:22:22 +09:00

View file

@ -292,7 +292,9 @@ void ColorPicker::build_ui_custom(Widget& root_container)
m_html_text->on_change = [this]() {
auto color_name = m_html_text->text();
auto optional_color = Color::from_string(color_name);
if (optional_color.has_value()) {
if (optional_color.has_value() && (!color_name.starts_with("#") || color_name.length() == ((m_color_has_alpha_channel) ? 9 : 7))) {
// The color length must be 9/7 (unless it is a name like red), because:
// - If we allowed 5/4 character rgb color, the field would reset to 9/7 characters after you deleted 4/3 characters.
auto color = optional_color.value();
if (m_color == color)
return;