فهرست منبع

LibGUI: Make ComboBox text editor release focus when Escape is pressed

kleines Filmröllchen 3 سال پیش
والد
کامیت
f922ffb032
1فایلهای تغییر یافته به همراه12 افزوده شده و 0 حذف شده
  1. 12 0
      Userland/Libraries/LibGUI/ComboBox.cpp

+ 12 - 0
Userland/Libraries/LibGUI/ComboBox.cpp

@@ -7,10 +7,12 @@
 #include <LibGUI/Button.h>
 #include <LibGUI/ComboBox.h>
 #include <LibGUI/Desktop.h>
+#include <LibGUI/Event.h>
 #include <LibGUI/ListView.h>
 #include <LibGUI/Model.h>
 #include <LibGUI/Scrollbar.h>
 #include <LibGUI/TextBox.h>
+#include <LibGUI/TextEditor.h>
 #include <LibGUI/Window.h>
 
 REGISTER_WIDGET(GUI, ComboBox)
@@ -36,6 +38,16 @@ private:
         if (on_mousewheel)
             on_mousewheel(event.wheel_delta());
     }
+
+    virtual void keydown_event(KeyEvent& event) override
+    {
+        if (event.key() == Key_Escape) {
+            if (is_focused())
+                set_focus(false);
+            event.accept();
+        } else
+            TextEditor::keydown_event(event);
+    }
 };
 
 ComboBox::ComboBox()