diff options
author | Christian Hergert <chergert@redhat.com> | 2022-11-18 10:56:32 -0800 |
---|---|---|
committer | Christian Hergert <chergert@redhat.com> | 2022-11-18 12:10:36 -0800 |
commit | 26c2549d96cdb7ebfe24622a3c86acdbdff50abb (patch) | |
tree | a8b05206e93a620ca7e2d05c3bbb326890965946 /gtksourceview | |
parent | 11bacbe15c83ab6b6ba4d7baf04d881aecce39b8 (diff) | |
download | gtksourceview-26c2549d96cdb7ebfe24622a3c86acdbdff50abb.tar.gz |
vim: ignore gtk_text_view_im_context_filter_keypress
There are cases while in INSERT mode that we need to handle to switch
to REPLACE as well as switching to literal input.
These all currently require the Control key or Escape along with the
Insert key. Filtering them would return FALSE, but unforutnatley if
they are not those, calling gtk_text_view_im_context_filter_keypress()
will cause the text to be committed before further GtkEventControllerKey
instances could process the input.
That breaks other GtkSourceView features such as indenters that might
trigger on the key-press. For example, Builder can reformat function
arguments on `)`. Without this, that code and other key-press handlers
would be completely skipped while in INSERT mode.
Diffstat (limited to 'gtksourceview')
-rw-r--r-- | gtksourceview/vim/gtksourceviminsert.c | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/gtksourceview/vim/gtksourceviminsert.c b/gtksourceview/vim/gtksourceviminsert.c index 477ff8b8..85347308 100644 --- a/gtksourceview/vim/gtksourceviminsert.c +++ b/gtksourceview/vim/gtksourceviminsert.c @@ -171,25 +171,38 @@ gtk_source_vim_insert_handle_event (GtkSourceVimState *state, g_assert (GTK_SOURCE_IS_VIM_INSERT (self)); g_assert (event != NULL); - if (!(view = gtk_source_vim_state_get_view (state))) + view = gtk_source_vim_state_get_view (state); + + /* We only handle keypress, otherwise defer to the normal event processing + * flow and/or input methods. + */ + if (view == NULL || gdk_event_get_event_type (event) != GDK_KEY_PRESS) + { return FALSE; + } + /* gtk_text_view_im_context_filter_keypress() will always filter input that + * can be converted into an GtkIMContext::commit emission so we must check + * to see if any of our handlers will check first. + * + * This has a sort of annoying impact with the underlying input method that + * we could collide, but there doesn't seem to be much we can do about that. + * + * https://gitlab.gnome.org/GNOME/gtk/-/issues/5349 + */ keyval = gdk_key_event_get_keyval (event); keycode = gdk_key_event_get_keycode (event); mods = gdk_event_get_modifier_state (event) & gtk_accelerator_get_default_mod_mask (); - /* Allow input methods to complete */ - if (gtk_text_view_im_context_filter_keypress (GTK_TEXT_VIEW (view), event)) - return TRUE; + gtk_source_vim_state_keyval_to_string (keyval, mods, string); - /* Only deal with presses after this */ - if (gdk_event_get_event_type (event) != GDK_KEY_PRESS) + if (GTK_SOURCE_VIM_STATE_GET_CLASS (self)->handle_keypress (state, keyval, keycode, mods, string)) + { return TRUE; + } - gtk_source_vim_state_keyval_to_string (keyval, mods, string); - - return GTK_SOURCE_VIM_STATE_GET_CLASS (self)->handle_keypress (state, keyval, keycode, mods, string); + return FALSE; } static void |