[gtksourceview/wip/chergert/vim] use char pending for capturing in motions
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/vim] use char pending for capturing in motions
- Date: Wed, 3 Nov 2021 21:20:37 +0000 (UTC)
commit e8aa3c1c1fea85090aab9618357f29751d2d8862
Author: Christian Hergert <chergert redhat com>
Date: Wed Nov 3 14:20:32 2021 -0700
use char pending for capturing in motions
gtksourceview/vim/gtk-source-vim-motion.c | 56 +++++++++++++++++++++++++------
1 file changed, 46 insertions(+), 10 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-motion.c b/gtksourceview/vim/gtk-source-vim-motion.c
index bc704118..c2b1149b 100644
--- a/gtksourceview/vim/gtk-source-vim-motion.c
+++ b/gtksourceview/vim/gtk-source-vim-motion.c
@@ -23,6 +23,7 @@
#include "gtksourceview.h"
+#include "gtk-source-vim-char-pending.h"
#include "gtk-source-vim-motion.h"
typedef gboolean (*Motion) (GtkTextIter *iter,
@@ -1284,6 +1285,27 @@ gtk_source_vim_motion_complete (GtkSourceVimMotion *self,
return TRUE;
}
+static gboolean
+gtk_source_vim_motion_begin_char_pending (GtkSourceVimMotion *self,
+ Motion motion,
+ Inclusivity inclusivity,
+ MotionWise wise)
+{
+ GtkSourceVimState *char_pending;
+
+ g_assert (GTK_SOURCE_IS_VIM_MOTION (self));
+ g_assert (motion != NULL);
+
+ self->motion = motion;
+ self->inclusivity = inclusivity;
+ self->wise = wise;
+
+ char_pending = gtk_source_vim_char_pending_new ();
+ gtk_source_vim_state_push (GTK_SOURCE_VIM_STATE (self), char_pending);
+
+ return TRUE;
+}
+
static gboolean
gtk_source_vim_motion_handle_keypress (GtkSourceVimState *state,
guint keyval,
@@ -1473,18 +1495,10 @@ gtk_source_vim_motion_handle_keypress (GtkSourceVimState *state,
return gtk_source_vim_motion_complete (self, motion_forward_WORD_end, INCLUSIVE,
CHARWISE);
case GDK_KEY_f:
- self->waiting_for_f_char = TRUE;
- self->motion = motion_f_char;
- self->inclusivity = EXCLUSIVE;
- self->wise = CHARWISE;
- return TRUE;
+ return gtk_source_vim_motion_begin_char_pending (self, motion_f_char, EXCLUSIVE,
CHARWISE);
case GDK_KEY_F:
- self->waiting_for_f_char = TRUE;
- self->motion = motion_F_char;
- self->inclusivity = INCLUSIVE;
- self->wise = CHARWISE;
- return TRUE;
+ return gtk_source_vim_motion_begin_char_pending (self, motion_F_char, INCLUSIVE,
CHARWISE);
case GDK_KEY_parenleft:
return gtk_source_vim_motion_complete (self, motion_backward_sentence_start,
INCLUSIVE, CHARWISE);
@@ -1569,6 +1583,27 @@ gtk_source_vim_motion_leave (GtkSourceVimState *state)
}
}
+static void
+gtk_source_vim_motion_resume (GtkSourceVimState *state,
+ GtkSourceVimState *from)
+{
+ GtkSourceVimMotion *self = (GtkSourceVimMotion *)state;
+
+ g_assert (GTK_SOURCE_IS_VIM_STATE (self));
+ g_assert (GTK_SOURCE_IS_VIM_STATE (from));
+
+ if (GTK_SOURCE_IS_VIM_CHAR_PENDING (from))
+ {
+ GtkSourceVimCharPending *pending = GTK_SOURCE_VIM_CHAR_PENDING (from);
+ gunichar ch = gtk_source_vim_char_pending_get_character (pending);
+ const char *str = gtk_source_vim_char_pending_get_string (pending);
+
+ self->f_char = ch;
+ g_string_append (self->command_text, str);
+ gtk_source_vim_state_pop (state);
+ }
+}
+
static void
gtk_source_vim_motion_append_command (GtkSourceVimState *state,
GString *string)
@@ -1612,6 +1647,7 @@ gtk_source_vim_motion_class_init (GtkSourceVimMotionClass *klass)
state_class->handle_keypress = gtk_source_vim_motion_handle_keypress;
state_class->leave = gtk_source_vim_motion_leave;
state_class->repeat = gtk_source_vim_motion_repeat;
+ state_class->resume = gtk_source_vim_motion_resume;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]