[geary/wip/730495-fix-inline-plain-text-paste-0.12: 17/18] Fix rich text being pasted by Ctrl+V in plain text embedded composers



commit d44214d0bc3c4ccdfcce0739027f7b20ee24cb08
Author: Michael James Gratton <mike vee net>
Date:   Thu Jul 26 11:15:51 2018 +1000

    Fix rich text being pasted by Ctrl+V in plain text embedded composers
    
    This restores normal key handling MainWindow:key_press_event when a
    keyboard modifier (Ctrl, Shift, etc) is down, keeping the ordering hack
    only for plain key presses, so that we can handle Ctrl+V before
    WebKitGTK does, and hence letting us paste plain text default when rich
    text is not enabled.
    
    Fixes Bug 730495.

 src/client/components/main-window.vala | 38 +++++++++++++++++++++++-----------
 ui/main-window.ui                      |  1 -
 2 files changed, 26 insertions(+), 13 deletions(-)
---
diff --git a/src/client/components/main-window.vala b/src/client/components/main-window.vala
index 0125440a..f4acb284 100644
--- a/src/client/components/main-window.vala
+++ b/src/client/components/main-window.vala
@@ -220,6 +220,7 @@ public class MainWindow : Gtk.ApplicationWindow, Geary.BaseInterface {
         return scrollbar != null && scrollbar.get_visible();
     }
 
+    /** {@inheritDoc} */
     public override bool key_press_event(Gdk.EventKey event) {
         check_shift_event(event);
 
@@ -258,16 +259,35 @@ public class MainWindow : Gtk.ApplicationWindow, Geary.BaseInterface {
          * [0] - <https://bugs.webkit.org/show_bug.cgi?id=136430>
          */
 
-        bool handled = propagate_key_event(event);
-        if (!handled) {
-            handled = activate_key(event);
-        }
-        if (!handled) {
-            handled = Gtk.bindings_activate_event(this, event);
+        bool handled = false;
+        if (event.state != 0 &&
+            event.state != Gdk.ModifierType.SHIFT_MASK) {
+            // Have a modifier (Ctrl, Alt, etc) so we don't need to
+            // worry about SKCs, so handle normally. Can't do this
+            // with Shift though since that will stop chars being
+            // typed in the composer that conflict with accells, like
+            // `!`.
+            handled = base.key_press_event(event);
+        } else {
+            // A modifier we don't care about is down is down, so
+            // kluge input handling to make SKCs per the above.
+            handled = propagate_key_event(event);
+            if (!handled) {
+                handled = activate_key(event);
+            }
+            if (!handled) {
+                handled = Gtk.bindings_activate_event(this, event);
+            }
         }
         return handled;
     }
 
+    /** {@inheritDoc} */
+    public override bool key_release_event(Gdk.EventKey event) {
+        check_shift_event(event);
+        return base.key_release_event(event);
+    }
+
     private void on_conversation_monitor_changed() {
         ConversationListStore? old_model = this.conversation_list_view.get_model();
         if (old_model != null) {
@@ -409,12 +429,6 @@ public class MainWindow : Gtk.ApplicationWindow, Geary.BaseInterface {
         }
     }
 
-    [GtkCallback]
-    private bool on_key_release_event(Gdk.EventKey event) {
-        check_shift_event(event);
-        return Gdk.EVENT_PROPAGATE;
-    }
-
     [GtkCallback]
     private bool on_focus_event() {
         on_shift_key(false);
diff --git a/ui/main-window.ui b/ui/main-window.ui
index 1ed5894b..468603fb 100644
--- a/ui/main-window.ui
+++ b/ui/main-window.ui
@@ -7,7 +7,6 @@
     <property name="name">GearyMainWindow</property>
     <property name="events">GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_FOCUS_CHANGE_MASK | 
GDK_STRUCTURE_MASK</property>
     <signal name="delete_event" handler="on_delete_event"/>
-    <signal name="key_release_event" handler="on_key_release_event"/>
     <signal name="focus_in_event" handler="on_focus_event"/>
     <child>
       <object class="GtkBox" id="main_layout">


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