Просмотр исходного кода

LibGUI: Add and use TextEditor::hide_autocomplete()

There were cases where the autocomplete box was being hidden but the
autocomplete timer wasn't being cancelled.
thislooksfun 3 лет назад
Родитель
Сommit
352f593958
2 измененных файлов с 14 добавлено и 7 удалено
  1. 13 7
      Userland/Libraries/LibGUI/TextEditor.cpp
  2. 1 0
      Userland/Libraries/LibGUI/TextEditor.h

+ 13 - 7
Userland/Libraries/LibGUI/TextEditor.cpp

@@ -740,12 +740,12 @@ void TextEditor::keydown_event(KeyEvent& event)
 {
 {
     if (m_autocomplete_box && m_autocomplete_box->is_visible() && (event.key() == KeyCode::Key_Return || event.key() == KeyCode::Key_Tab)) {
     if (m_autocomplete_box && m_autocomplete_box->is_visible() && (event.key() == KeyCode::Key_Return || event.key() == KeyCode::Key_Tab)) {
         m_autocomplete_box->apply_suggestion();
         m_autocomplete_box->apply_suggestion();
-        m_autocomplete_box->close();
+        hide_autocomplete();
         return;
         return;
     }
     }
 
 
     if (m_autocomplete_box && m_autocomplete_box->is_visible() && event.key() == KeyCode::Key_Escape) {
     if (m_autocomplete_box && m_autocomplete_box->is_visible() && event.key() == KeyCode::Key_Escape) {
-        m_autocomplete_box->close();
+        hide_autocomplete();
         return;
         return;
     }
     }
 
 
@@ -826,13 +826,13 @@ void TextEditor::keydown_event(KeyEvent& event)
 
 
     if (event.modifiers() == Mod_Shift && event.key() == KeyCode::Key_Delete) {
     if (event.modifiers() == Mod_Shift && event.key() == KeyCode::Key_Delete) {
         if (m_autocomplete_box)
         if (m_autocomplete_box)
-            m_autocomplete_box->close();
+            hide_autocomplete();
         return;
         return;
     }
     }
 
 
     if (event.key() == KeyCode::Key_Delete) {
     if (event.key() == KeyCode::Key_Delete) {
         if (m_autocomplete_box)
         if (m_autocomplete_box)
-            m_autocomplete_box->close();
+            hide_autocomplete();
         return;
         return;
     }
     }
 
 
@@ -840,7 +840,7 @@ void TextEditor::keydown_event(KeyEvent& event)
         if (!is_editable())
         if (!is_editable())
             return;
             return;
         if (m_autocomplete_box)
         if (m_autocomplete_box)
-            m_autocomplete_box->close();
+            hide_autocomplete();
         if (has_selection()) {
         if (has_selection()) {
             delete_selection();
             delete_selection();
             did_update_selection();
             did_update_selection();
@@ -1481,7 +1481,13 @@ void TextEditor::force_update_autocomplete(Function<void()> callback)
 
 
 void TextEditor::hide_autocomplete_if_needed()
 void TextEditor::hide_autocomplete_if_needed()
 {
 {
-    if (m_autocomplete_box && !m_should_keep_autocomplete_box) {
+    if (!m_should_keep_autocomplete_box)
+        hide_autocomplete();
+}
+
+void TextEditor::hide_autocomplete()
+{
+    if (m_autocomplete_box) {
         m_autocomplete_box->close();
         m_autocomplete_box->close();
         if (m_autocomplete_timer)
         if (m_autocomplete_timer)
             m_autocomplete_timer->stop();
             m_autocomplete_timer->stop();
@@ -1913,7 +1919,7 @@ void TextEditor::set_autocomplete_provider(OwnPtr<AutocompleteProvider>&& provid
             m_autocomplete_box = make<AutocompleteBox>(*this);
             m_autocomplete_box = make<AutocompleteBox>(*this);
     }
     }
     if (m_autocomplete_box)
     if (m_autocomplete_box)
-        m_autocomplete_box->close();
+        hide_autocomplete();
 }
 }
 
 
 EditingEngine const* TextEditor::editing_engine() const
 EditingEngine const* TextEditor::editing_engine() const

+ 1 - 0
Userland/Libraries/LibGUI/TextEditor.h

@@ -282,6 +282,7 @@ private:
     void try_update_autocomplete(Function<void()> callback = {});
     void try_update_autocomplete(Function<void()> callback = {});
     void force_update_autocomplete(Function<void()> callback = {});
     void force_update_autocomplete(Function<void()> callback = {});
     void hide_autocomplete_if_needed();
     void hide_autocomplete_if_needed();
+    void hide_autocomplete();
 
 
     int icon_size() const { return 16; }
     int icon_size() const { return 16; }
     int icon_padding() const { return 2; }
     int icon_padding() const { return 2; }