diff options
author | Peter Elliott <pelliott@ualberta.ca> | 2020-09-16 17:28:34 -0700 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-09-17 09:47:05 +0200 |
commit | 9670d9ad50fd0fb33b5fbef4af11bb102ad0478c (patch) | |
tree | d24c8c2846aef6f223689ee30c38ed248fbde684 /Libraries | |
parent | d89cad7c571184a75a99e0be154f702f6e3510b9 (diff) | |
download | serenity-9670d9ad50fd0fb33b5fbef4af11bb102ad0478c.zip |
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.
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibGUI/ColorPicker.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/Libraries/LibGUI/ColorPicker.cpp b/Libraries/LibGUI/ColorPicker.cpp index 3466db44a2..390d212a01 100644 --- a/Libraries/LibGUI/ColorPicker.cpp +++ b/Libraries/LibGUI/ColorPicker.cpp @@ -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; |