From ae6aed8ae6006f45e2c3e5008546cb2ee2fdbdd0 Mon Sep 17 00:00:00 2001 From: Michael James Gratton Date: Thu, 26 Jul 2018 11:15:51 +1000 Subject: [PATCH] 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 7e5ab0ef..ecab6280 100644 --- a/src/client/components/main-window.vala +++ b/src/client/components/main-window.vala @@ -248,6 +248,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); @@ -286,16 +287,35 @@ public class MainWindow : Gtk.ApplicationWindow, Geary.BaseInterface { * [0] - */ - 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) { @@ -432,12 +452,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 ae2aa252..367e7566 100644 --- a/ui/main-window.ui +++ b/ui/main-window.ui @@ -9,7 +9,6 @@ False - True