[geary] Ctrl+Enter to send w/ inline composer: Closes bug #730542



commit 0e1dc9188abcd05bd6cc7925cc9b4d5641361af7
Author: Jim Nelson <jim yorba org>
Date:   Wed May 21 15:52:05 2014 -0700

    Ctrl+Enter to send w/ inline composer: Closes bug #730542
    
    Under refactored composer, the widget key_press_event handler wasn't
    receiving modified keystrokes, just the keypresses of the modifiers
    themselves (i.e. it would recv "Control" but not the "Control+Enter"
    which followed).  This works around the problem.

 src/client/composer/composer-widget.vala |   22 ++++++++++++++++++----
 1 files changed, 18 insertions(+), 4 deletions(-)
---
diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index a146e28..35f7bed 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -471,7 +471,7 @@ public class ComposerWidget : Gtk.EventBox {
         editor.undo.connect(update_actions);
         editor.redo.connect(update_actions);
         editor.selection_changed.connect(update_actions);
-        editor.key_press_event.connect(on_key_press);
+        editor.key_press_event.connect(on_editor_key_press);
         editor.user_changed_contents.connect(reset_draft_timer);
         
         // only do this after setting body_html
@@ -1582,14 +1582,20 @@ public class ComposerWidget : Gtk.EventBox {
         editor.settings.enable_spell_checking = GearyApplication.instance.config.spell_check;
     }
     
+    // This overrides the keypress handling for the *widget*; the WebView editor's keypress overrides
+    // are handled by on_editor_key_press
     public override bool key_press_event(Gdk.EventKey event) {
         update_actions();
         
         switch (Gdk.keyval_name(event.keyval)) {
             case "Return":
             case "KP_Enter":
-                if ((event.state & Gdk.ModifierType.CONTROL_MASK) != 0 && send_button.sensitive) {
-                    on_send();
+                // always trap Ctrl+Enter/Ctrl+KeypadEnter to prevent the Enter leaking through
+                // to the controls, but only send if send is available
+                if ((event.state & Gdk.ModifierType.CONTROL_MASK) != 0) {
+                    if (send_button.sensitive)
+                        on_send();
+                    
                     return true;
                 }
             break;
@@ -1684,7 +1690,15 @@ public class ComposerWidget : Gtk.EventBox {
         return false;
     }
     
-    private bool on_key_press(Gdk.EventKey event) {
+    private bool on_editor_key_press(Gdk.EventKey event) {
+        // widget's keypress override doesn't receive non-modifier keys when the editor processes
+        // them, regardless if true or false is called; this deals with that issue (specifically
+        // so Ctrl+Enter will send the message)
+        if (event.is_modifier == 0) {
+            if (key_press_event(event))
+                return true;
+        }
+        
         if ((event.state & Gdk.ModifierType.MOD1_MASK) != 0)
             return false;
         


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