[gtksourceview/wip/chergert/vim] allow using handle_keypress in some cases for insert
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/vim] allow using handle_keypress in some cases for insert
- Date: Sun, 7 Nov 2021 20:57:20 +0000 (UTC)
commit 7d58d0e754df3f8a247865097fab97da2b63e8a3
Author: Christian Hergert <chergert redhat com>
Date: Sun Nov 7 12:57:03 2021 -0800
allow using handle_keypress in some cases for insert
this might make it easier to test later on
gtksourceview/vim/gtk-source-vim-insert.c | 80 +++++++++++++++++++------------
1 file changed, 50 insertions(+), 30 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-insert.c b/gtksourceview/vim/gtk-source-vim-insert.c
index 74d60924..8fbfdee1 100644
--- a/gtksourceview/vim/gtk-source-vim-insert.c
+++ b/gtksourceview/vim/gtk-source-vim-insert.c
@@ -93,31 +93,16 @@ clear_to_first_char (GtkSourceVimInsert *self)
}
static gboolean
-gtk_source_vim_insert_handle_event (GtkSourceVimState *state,
- GdkEvent *event)
+gtk_source_vim_insert_handle_keypress (GtkSourceVimState *state,
+ guint keyval,
+ guint keycode,
+ GdkModifierType mods,
+ const char *string)
{
GtkSourceVimInsert *self = (GtkSourceVimInsert *)state;
- GtkSourceView *view;
- GdkModifierType mods;
- guint keyval;
-
- g_assert (GTK_SOURCE_IS_VIM_INSERT (self));
- g_assert (event != NULL);
-
- if (!(view = gtk_source_vim_state_get_view (state)))
- return FALSE;
-
- keyval = gdk_key_event_get_keyval (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;
- /* Only deal with presses after this */
- if (gdk_event_get_event_type (event) != GDK_KEY_PRESS)
- return TRUE;
+ g_assert (GTK_SOURCE_IS_VIM_STATE (state));
+ g_assert (string != NULL);
/* Leave insert mode if Escape,ctrl+[,ctrl+c was pressed */
if (gtk_source_vim_state_is_escape (keyval, mods) ||
@@ -144,24 +129,58 @@ gtk_source_vim_insert_handle_event (GtkSourceVimState *state,
}
}
+ /* XXX: Currently we do not use overwrite mode while in insert even
+ * though that is the only way to get a block cursor. To do that we'd
+ * have to be able to commit text to the textview through the input
+ * method and we don't have a way to do that yet.
+ */
+
switch (keyval)
{
case GDK_KEY_Insert:
gtk_source_vim_state_push (GTK_SOURCE_VIM_STATE (self),
gtk_source_vim_replace_new ());
- break;
+ return TRUE;
default:
- break;
+ return FALSE;
}
+}
- /* XXX: Currently we do not use overwrite mode while in insert even
- * though that is the only way to get a block cursor. To do that we'd
- * have to be able to commit text to the textview through the input
- * method and we don't have a way to do that yet.
- */
+static gboolean
+gtk_source_vim_insert_handle_event (GtkSourceVimState *state,
+ GdkEvent *event)
+{
+ GtkSourceVimInsert *self = (GtkSourceVimInsert *)state;
+ GtkSourceView *view;
+ char string[16];
+ GdkModifierType mods;
+ guint keyval;
+ guint keycode;
+
+ g_assert (GTK_SOURCE_IS_VIM_INSERT (self));
+ g_assert (event != NULL);
+
+ if (!(view = gtk_source_vim_state_get_view (state)))
+ return FALSE;
+
+ 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;
+
+ /* Only deal with presses after this */
+ if (gdk_event_get_event_type (event) != GDK_KEY_PRESS)
+ return TRUE;
+
+
+ gtk_source_vim_state_keyval_to_string (keyval, mods, string);
- return FALSE;
+ return GTK_SOURCE_VIM_STATE_GET_CLASS (self)->handle_keypress (state, keyval, keycode, mods, string);
}
static void
@@ -460,6 +479,7 @@ gtk_source_vim_insert_class_init (GtkSourceVimInsertClass *klass)
state_class->command_bar_text = _("-- INSERT --");
state_class->append_command = gtk_source_vim_insert_append_command;
state_class->handle_event = gtk_source_vim_insert_handle_event;
+ state_class->handle_keypress = gtk_source_vim_insert_handle_keypress;
state_class->resume = gtk_source_vim_insert_resume;
state_class->enter = gtk_source_vim_insert_enter;
state_class->leave = gtk_source_vim_insert_leave;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]