[gtksourceview/wip/chergert/vim] track counts
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/vim] track counts
- Date: Wed, 3 Nov 2021 23:50:17 +0000 (UTC)
commit 924e42487e72c69b559639445b88552dfb3feaaa
Author: Christian Hergert <chergert redhat com>
Date: Wed Nov 3 16:49:38 2021 -0700
track counts
gtksourceview/vim/gtk-source-vim-visual.c | 41 +++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
---
diff --git a/gtksourceview/vim/gtk-source-vim-visual.c b/gtksourceview/vim/gtk-source-vim-visual.c
index b7532ae5..135d6305 100644
--- a/gtksourceview/vim/gtk-source-vim-visual.c
+++ b/gtksourceview/vim/gtk-source-vim-visual.c
@@ -61,6 +61,8 @@ struct _GtkSourceVimVisual
GtkTextMark *started_at;
GtkTextMark *cursor;
+
+ int count;
};
typedef struct
@@ -168,6 +170,7 @@ static void
gtk_source_vim_visual_clear (GtkSourceVimVisual *self)
{
self->handler = key_handler_initial;
+ self->count = 0;
}
static gboolean
@@ -354,16 +357,20 @@ gtk_source_vim_visual_begin_command (GtkSourceVimVisual *self,
const char *command)
{
CursorInfo info;
+ int count;
g_assert (GTK_SOURCE_IS_VIM_VISUAL (self));
g_assert (command != NULL);
+ count = self->count, self->count = 0;
+
gtk_source_vim_visual_clear (self);
g_clear_object (&self->command);
cursor_info_stash (self, &info);
self->command = gtk_source_vim_command_new (command);
+ gtk_source_vim_state_set_count (self->command, count);
gtk_source_vim_state_set_parent (self->command, GTK_SOURCE_VIM_STATE (self));
gtk_source_vim_state_repeat (self->command);
@@ -406,11 +413,15 @@ gtk_source_vim_visual_try_motion (GtkSourceVimVisual *self,
const char *str)
{
GtkSourceVimState *motion;
+ int count;
g_assert (GTK_SOURCE_IS_VIM_VISUAL (self));
+ count = self->count, self->count = 0;
+
/* Try to apply a motion to our cursor */
motion = gtk_source_vim_motion_new ();
+ gtk_source_vim_state_set_count (motion, count);
gtk_source_vim_motion_set_mark (GTK_SOURCE_VIM_MOTION (motion), self->cursor);
gtk_source_vim_state_push (GTK_SOURCE_VIM_STATE (self), motion);
gtk_source_vim_state_synthesize (motion, keyval, mods);
@@ -517,8 +528,38 @@ key_handler_initial (GtkSourceVimVisual *self,
}
}
+ if (self->count == 0)
+ {
+ switch (keyval)
+ {
+ case GDK_KEY_0:
+ case GDK_KEY_KP_0:
+ goto try_visual_motion;
+
+ default:
+ break;
+ }
+ }
+
switch (keyval)
{
+ case GDK_KEY_0: case GDK_KEY_KP_0:
+ case GDK_KEY_1: case GDK_KEY_KP_1:
+ case GDK_KEY_2: case GDK_KEY_KP_2:
+ case GDK_KEY_3: case GDK_KEY_KP_3:
+ case GDK_KEY_4: case GDK_KEY_KP_4:
+ case GDK_KEY_5: case GDK_KEY_KP_5:
+ case GDK_KEY_6: case GDK_KEY_KP_6:
+ case GDK_KEY_7: case GDK_KEY_KP_7:
+ case GDK_KEY_8: case GDK_KEY_KP_8:
+ case GDK_KEY_9: case GDK_KEY_KP_9:
+ self->count *= 10;
+ if (keyval >= GDK_KEY_0 && keyval <= GDK_KEY_9)
+ self->count += keyval - GDK_KEY_0;
+ else if (keyval >= GDK_KEY_KP_0 && keyval <= GDK_KEY_KP_9)
+ self->count += keyval - GDK_KEY_KP_0;
+ return TRUE;
+
case GDK_KEY_z:
self->handler = key_handler_z;
return TRUE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]