[gtksourceview/wip/chergert/vim] make c with motion work
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/vim] make c with motion work
- Date: Sun, 7 Nov 2021 20:34:02 +0000 (UTC)
commit b844f9f90c2543ba179ad1f3a5ebeab461926be2
Author: Christian Hergert <chergert redhat com>
Date: Sun Nov 7 12:33:57 2021 -0800
make c with motion work
gtksourceview/vim/gtk-source-vim-insert.c | 56 ++++++++++++++++++-------------
gtksourceview/vim/gtk-source-vim-normal.c | 24 ++++++++++++-
2 files changed, 56 insertions(+), 24 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-insert.c b/gtksourceview/vim/gtk-source-vim-insert.c
index 6d64d93d..74d60924 100644
--- a/gtksourceview/vim/gtk-source-vim-insert.c
+++ b/gtksourceview/vim/gtk-source-vim-insert.c
@@ -164,29 +164,6 @@ gtk_source_vim_insert_handle_event (GtkSourceVimState *state,
return FALSE;
}
-static void
-gtk_source_vim_insert_resume (GtkSourceVimState *state,
- GtkSourceVimState *from)
-{
- g_assert (GTK_SOURCE_IS_VIM_INSERT (state));
- g_assert (GTK_SOURCE_IS_VIM_STATE (from));
-
- gtk_source_vim_state_set_overwrite (state, FALSE);
-
- if (GTK_SOURCE_IS_VIM_REPLACE (from))
- {
- /* If we are leaving replace mode back to insert then
- * we need also exit insert mode so we end up back on
- * Normal mode.
- */
- gtk_source_vim_state_unparent (from);
- gtk_source_vim_state_pop (state);
- return;
- }
-
- gtk_source_vim_state_unparent (from);
-}
-
static void
gtk_source_vim_insert_prepare (GtkSourceVimInsert *self)
{
@@ -297,6 +274,39 @@ gtk_source_vim_insert_prepare (GtkSourceVimInsert *self)
}
}
+static void
+gtk_source_vim_insert_resume (GtkSourceVimState *state,
+ GtkSourceVimState *from)
+{
+ GtkSourceVimInsert *self = (GtkSourceVimInsert *)state;
+
+ g_assert (GTK_SOURCE_IS_VIM_INSERT (state));
+ g_assert (GTK_SOURCE_IS_VIM_STATE (from));
+
+ gtk_source_vim_state_set_overwrite (state, FALSE);
+
+ if (GTK_SOURCE_IS_VIM_MOTION (from) && self->motion == NULL)
+ {
+ gtk_source_vim_state_reparent (from, self, &self->motion);
+ gtk_source_vim_text_history_end (self->history);
+ gtk_source_vim_insert_prepare (self);
+ gtk_source_vim_text_history_begin (self->history);
+ return;
+ }
+ else if (GTK_SOURCE_IS_VIM_REPLACE (from))
+ {
+ /* If we are leaving replace mode back to insert then
+ * we need also exit insert mode so we end up back on
+ * Normal mode.
+ */
+ gtk_source_vim_state_unparent (from);
+ gtk_source_vim_state_pop (state);
+ return;
+ }
+
+ gtk_source_vim_state_unparent (from);
+}
+
static void
gtk_source_vim_insert_enter (GtkSourceVimState *state)
{
diff --git a/gtksourceview/vim/gtk-source-vim-normal.c b/gtksourceview/vim/gtk-source-vim-normal.c
index e192b11f..8e6b9b4c 100644
--- a/gtksourceview/vim/gtk-source-vim-normal.c
+++ b/gtksourceview/vim/gtk-source-vim-normal.c
@@ -809,7 +809,29 @@ key_handler_c (GtkSourceVimNormal *self,
return TRUE;
default:
- return gtk_source_vim_normal_bail (self);
+ {
+ GtkSourceVimState *motion;
+ GtkSourceVimState *selection;
+ GtkSourceVimState *insert;
+ int count;
+
+ count = self->count, self->count = 0;
+ insert = gtk_source_vim_insert_new ();
+ motion = gtk_source_vim_motion_new ();
+ selection = gtk_source_vim_motion_new_none ();
+ gtk_source_vim_motion_set_apply_on_leave (GTK_SOURCE_VIM_MOTION (motion), FALSE);
+ gtk_source_vim_insert_set_selection_motion (GTK_SOURCE_VIM_INSERT (insert),
GTK_SOURCE_VIM_MOTION (selection));
+ gtk_source_vim_state_set_count (motion, count);
+ gtk_source_vim_state_push (GTK_SOURCE_VIM_STATE (self), insert);
+ gtk_source_vim_state_push (GTK_SOURCE_VIM_STATE (insert), motion);
+ gtk_source_vim_state_synthesize (motion, keyval, mods);
+
+ gtk_source_vim_normal_clear (self);
+
+ g_object_unref (selection);
+
+ return TRUE;
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]