Jelajahi Sumber

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.
Peter Elliott 4 tahun lalu
induk
melakukan
9670d9ad50
1 mengubah file dengan 3 tambahan dan 1 penghapusan
  1. 3 1
      Libraries/LibGUI/ColorPicker.cpp

+ 3 - 1
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;