[geary/mjog/577-close-composer-completion: 2/2] Fix composer being dismissed when completion visible on Esc



commit b9517d81e90e9fbe5727f8837250c59f290692e1
Author: Michael Gratton <mike vee net>
Date:   Mon Feb 24 10:02:23 2020 +1100

    Fix composer being dismissed when completion visible on Esc
    
    Addresses comment in #577

 src/client/composer/composer-email-entry.vala | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
---
diff --git a/src/client/composer/composer-email-entry.vala b/src/client/composer/composer-email-entry.vala
index 977d6222..b5e87314 100644
--- a/src/client/composer/composer-email-entry.vala
+++ b/src/client/composer/composer-email-entry.vala
@@ -88,26 +88,33 @@ public class Composer.EmailEntry : Gtk.Entry {
     }
 
     private bool on_key_press(Gtk.Widget widget, Gdk.EventKey event) {
-        bool ret = Gdk.EVENT_PROPAGATE;
+        bool propagate = Gdk.EVENT_PROPAGATE;
         if (event.keyval == Gdk.Key.Tab) {
+            // If there is a completion entry selected, then use that
             ContactEntryCompletion? completion = (
                 get_completion() as ContactEntryCompletion
             );
             if (completion != null) {
                 completion.trigger_selection();
                 composer.child_focus(Gtk.DirectionType.TAB_FORWARD);
-                ret = Gdk.EVENT_STOP;
+                propagate = Gdk.EVENT_STOP;
             }
-        } else {
+        }
+
+        if (propagate == Gdk.EVENT_PROPAGATE &&
+            event.keyval != Gdk.Key.Escape) {
             // Keyboard shortcuts for undo/redo won't work when the
             // completion UI is visible unless we explicitly check for
-            // them there. This may be related to the
-            // single-key-shortcut handling hack in the MainWindow.
+            // them there.
+            //
+            // However, don't forward it on if the button pressed is
+            // Escape, so that the completion is hidden if present
+            // before the composer is closed.
             Gtk.Window? window = get_toplevel() as Gtk.Window;
             if (window != null) {
-                ret = window.activate_key(event);
+                propagate = window.activate_key(event);
             }
         }
-        return ret;
+        return propagate;
     }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]