[gtksourceview/wip/chergert/vim] clean c handling, implement cc, implement s
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/vim] clean c handling, implement cc, implement s
- Date: Fri, 29 Oct 2021 00:09:29 +0000 (UTC)
commit d45cd6f76201d8a770b9c90caade49f395e06c4d
Author: Christian Hergert <chergert redhat com>
Date: Thu Oct 28 17:09:08 2021 -0700
clean c handling, implement cc, implement s
gtksourceview/vim/gtk-source-vim-normal.c | 241 ++++++++++++++++--------------
1 file changed, 130 insertions(+), 111 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-normal.c b/gtksourceview/vim/gtk-source-vim-normal.c
index f797bda5..ce557c25 100644
--- a/gtksourceview/vim/gtk-source-vim-normal.c
+++ b/gtksourceview/vim/gtk-source-vim-normal.c
@@ -84,108 +84,6 @@ gtk_source_vim_normal_bail (GtkSourceVimNormal *self)
return TRUE;
}
-static void
-go_backward_char (GtkSourceVimNormal *self)
-{
- GtkTextIter iter;
-
- g_assert (GTK_SOURCE_IS_VIM_NORMAL (self));
-
- gtk_source_vim_state_get_buffer (GTK_SOURCE_VIM_STATE (self), &iter, NULL);
- if (!gtk_text_iter_starts_line (&iter) && gtk_text_iter_backward_char (&iter))
- gtk_source_vim_state_select (GTK_SOURCE_VIM_STATE (self), &iter, &iter);
-}
-
-static void
-keep_on_last_char (GtkSourceVimNormal *self)
-{
- GtkTextIter iter;
-
- g_assert (GTK_SOURCE_IS_VIM_NORMAL (self));
-
- gtk_source_vim_state_get_buffer (GTK_SOURCE_VIM_STATE (self), &iter, NULL);
-
- if (!gtk_text_iter_starts_line (&iter) && gtk_text_iter_ends_line (&iter))
- {
- gtk_text_iter_backward_char (&iter);
- gtk_source_vim_state_select (GTK_SOURCE_VIM_STATE (self), &iter, &iter);
- }
-}
-
-static gboolean
-key_handler_count (GtkSourceVimNormal *self,
- guint keyval,
- guint keycode,
- GdkModifierType mods,
- const char *string)
-{
- int n;
-
- g_assert (GTK_SOURCE_IS_VIM_NORMAL (self));
-
- self->has_count = TRUE;
-
- switch (keyval)
- {
- case GDK_KEY_0: case GDK_KEY_KP_0: n = 0; break;
- case GDK_KEY_1: case GDK_KEY_KP_1: n = 1; break;
- case GDK_KEY_2: case GDK_KEY_KP_2: n = 2; break;
- case GDK_KEY_3: case GDK_KEY_KP_3: n = 3; break;
- case GDK_KEY_4: case GDK_KEY_KP_4: n = 4; break;
- case GDK_KEY_5: case GDK_KEY_KP_5: n = 5; break;
- case GDK_KEY_6: case GDK_KEY_KP_6: n = 6; break;
- case GDK_KEY_7: case GDK_KEY_KP_7: n = 7; break;
- case GDK_KEY_8: case GDK_KEY_KP_8: n = 8; break;
- case GDK_KEY_9: case GDK_KEY_KP_9: n = 9; break;
-
- default:
- self->handler = key_handler_initial;
- return self->handler (self, keyval, keycode, mods, string);
- }
-
- self->count = self->count * 10 + n;
-
- return TRUE;
-}
-
-static gboolean
-key_handler_undo (GtkSourceVimNormal *self,
- guint keyval,
- guint keycode,
- GdkModifierType mods,
- const char *string)
-{
- GtkSourceBuffer *buffer;
-
- g_assert (GTK_SOURCE_IS_VIM_NORMAL (self));
-
- buffer = gtk_source_vim_state_get_buffer (GTK_SOURCE_VIM_STATE (self), NULL, NULL);
-
- /* TODO: ideally we'd land on the position we were before the undo, but
- * the undo stack in GTK does not do that yet.
- */
-
- switch (keyval)
- {
- case GDK_KEY_u:
- REPLAY (gtk_text_buffer_undo (GTK_TEXT_BUFFER (buffer)));
- keep_on_last_char (self);
- break;
-
- case GDK_KEY_r:
- REPLAY (gtk_text_buffer_redo (GTK_TEXT_BUFFER (buffer)));
- keep_on_last_char (self);
- break;
-
- default:
- return gtk_source_vim_normal_bail (self);
- }
-
- gtk_source_vim_normal_clear (self);
-
- return TRUE;
-}
-
G_GNUC_NULL_TERMINATED
static void
gtk_source_vim_normal_begin_delete (GtkSourceVimNormal *self,
@@ -290,6 +188,108 @@ gtk_source_vim_normal_begin_insert (GtkSourceVimNormal *self,
return ret;
}
+static void
+go_backward_char (GtkSourceVimNormal *self)
+{
+ GtkTextIter iter;
+
+ g_assert (GTK_SOURCE_IS_VIM_NORMAL (self));
+
+ gtk_source_vim_state_get_buffer (GTK_SOURCE_VIM_STATE (self), &iter, NULL);
+ if (!gtk_text_iter_starts_line (&iter) && gtk_text_iter_backward_char (&iter))
+ gtk_source_vim_state_select (GTK_SOURCE_VIM_STATE (self), &iter, &iter);
+}
+
+static void
+keep_on_last_char (GtkSourceVimNormal *self)
+{
+ GtkTextIter iter;
+
+ g_assert (GTK_SOURCE_IS_VIM_NORMAL (self));
+
+ gtk_source_vim_state_get_buffer (GTK_SOURCE_VIM_STATE (self), &iter, NULL);
+
+ if (!gtk_text_iter_starts_line (&iter) && gtk_text_iter_ends_line (&iter))
+ {
+ gtk_text_iter_backward_char (&iter);
+ gtk_source_vim_state_select (GTK_SOURCE_VIM_STATE (self), &iter, &iter);
+ }
+}
+
+static gboolean
+key_handler_count (GtkSourceVimNormal *self,
+ guint keyval,
+ guint keycode,
+ GdkModifierType mods,
+ const char *string)
+{
+ int n;
+
+ g_assert (GTK_SOURCE_IS_VIM_NORMAL (self));
+
+ self->has_count = TRUE;
+
+ switch (keyval)
+ {
+ case GDK_KEY_0: case GDK_KEY_KP_0: n = 0; break;
+ case GDK_KEY_1: case GDK_KEY_KP_1: n = 1; break;
+ case GDK_KEY_2: case GDK_KEY_KP_2: n = 2; break;
+ case GDK_KEY_3: case GDK_KEY_KP_3: n = 3; break;
+ case GDK_KEY_4: case GDK_KEY_KP_4: n = 4; break;
+ case GDK_KEY_5: case GDK_KEY_KP_5: n = 5; break;
+ case GDK_KEY_6: case GDK_KEY_KP_6: n = 6; break;
+ case GDK_KEY_7: case GDK_KEY_KP_7: n = 7; break;
+ case GDK_KEY_8: case GDK_KEY_KP_8: n = 8; break;
+ case GDK_KEY_9: case GDK_KEY_KP_9: n = 9; break;
+
+ default:
+ self->handler = key_handler_initial;
+ return self->handler (self, keyval, keycode, mods, string);
+ }
+
+ self->count = self->count * 10 + n;
+
+ return TRUE;
+}
+
+static gboolean
+key_handler_undo (GtkSourceVimNormal *self,
+ guint keyval,
+ guint keycode,
+ GdkModifierType mods,
+ const char *string)
+{
+ GtkSourceBuffer *buffer;
+
+ g_assert (GTK_SOURCE_IS_VIM_NORMAL (self));
+
+ buffer = gtk_source_vim_state_get_buffer (GTK_SOURCE_VIM_STATE (self), NULL, NULL);
+
+ /* TODO: ideally we'd land on the position we were before the undo, but
+ * the undo stack in GTK does not do that yet.
+ */
+
+ switch (keyval)
+ {
+ case GDK_KEY_u:
+ REPLAY (gtk_text_buffer_undo (GTK_TEXT_BUFFER (buffer)));
+ keep_on_last_char (self);
+ break;
+
+ case GDK_KEY_r:
+ REPLAY (gtk_text_buffer_redo (GTK_TEXT_BUFFER (buffer)));
+ keep_on_last_char (self);
+ break;
+
+ default:
+ return gtk_source_vim_normal_bail (self);
+ }
+
+ gtk_source_vim_normal_clear (self);
+
+ return TRUE;
+}
+
static gboolean
key_handler_command (GtkSourceVimNormal *self,
guint keyval,
@@ -387,12 +387,19 @@ key_handler_command (GtkSourceVimNormal *self,
NULL);
return TRUE;
+ case GDK_KEY_s:
+ gtk_source_vim_normal_begin_change (self,
+ gtk_source_vim_motion_new_forward_char (),
+ gtk_source_vim_motion_new_none (),
+ GTK_SOURCE_VIM_INSERT_HERE,
+ NULL);
+ break;
+
case GDK_KEY_asciitilde:
case GDK_KEY_J:
case GDK_KEY_p:
case GDK_KEY_P:
case GDK_KEY_period:
- case GDK_KEY_s:
case GDK_KEY_equal:
case GDK_KEY_plus:
break;
@@ -496,15 +503,27 @@ key_handler_viewport (GtkSourceVimNormal *self,
}
static gboolean
-key_handler_change (GtkSourceVimNormal *self,
- guint keyval,
- guint keycode,
- GdkModifierType mods,
- const char *string)
+key_handler_c (GtkSourceVimNormal *self,
+ guint keyval,
+ guint keycode,
+ GdkModifierType mods,
+ const char *string)
{
g_assert (GTK_SOURCE_IS_VIM_NORMAL (self));
- return TRUE;
+ switch (keyval)
+ {
+ case GDK_KEY_c:
+ gtk_source_vim_normal_begin_change (self,
+ gtk_source_vim_motion_new_line_end_with_nl (),
+ gtk_source_vim_motion_new_line_start (),
+ GTK_SOURCE_VIM_INSERT_HERE,
+ NULL);
+ return TRUE;
+
+ default:
+ return gtk_source_vim_normal_bail (self);
+ }
}
static gboolean
@@ -833,8 +852,8 @@ key_handler_initial (GtkSourceVimNormal *self,
break;
case GDK_KEY_c:
- self->handler = key_handler_change;
- break;
+ self->handler = key_handler_c;
+ return TRUE;
case GDK_KEY_g:
self->handler = key_handler_g;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]