[gtksourceview/wip/chergert/vim] implement undo/redo from normal
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/vim] implement undo/redo from normal
- Date: Wed, 27 Oct 2021 14:43:05 +0000 (UTC)
commit 91a8e5012c440971321a9e724932f237da672bc7
Author: Christian Hergert <chergert redhat com>
Date: Wed Oct 27 07:40:56 2021 -0700
implement undo/redo from normal
gtksourceview/vim/gtk-source-vim-normal.c | 45 ++++++++++++++++++++++++++++---
1 file changed, 42 insertions(+), 3 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-normal.c b/gtksourceview/vim/gtk-source-vim-normal.c
index 1780e35d..52134826 100644
--- a/gtksourceview/vim/gtk-source-vim-normal.c
+++ b/gtksourceview/vim/gtk-source-vim-normal.c
@@ -27,6 +27,8 @@
#include "gtk-source-vim-normal.h"
#include "gtk-source-vim-replace.h"
+#define REPEAT(_block) do { _block; } while (--self->repeat > 0);
+
typedef gboolean (*KeyHandler) (GtkSourceVimNormal *self,
guint keyval,
guint keycode,
@@ -127,6 +129,38 @@ begin_insert (GtkSourceVimNormal *self,
gtk_source_vim_state_push (GTK_SOURCE_VIM_STATE (self), gtk_source_vim_insert_new ());
}
+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);
+
+ switch (keyval)
+ {
+ case GDK_KEY_u:
+ REPEAT (gtk_text_buffer_undo (GTK_TEXT_BUFFER (buffer)));
+ break;
+
+ case GDK_KEY_r:
+ REPEAT (gtk_text_buffer_redo (GTK_TEXT_BUFFER (buffer)));
+ 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,
@@ -172,7 +206,6 @@ key_handler_command (GtkSourceVimNormal *self,
case GDK_KEY_period:
case GDK_KEY_s:
case GDK_KEY_S:
- case GDK_KEY_u:
case GDK_KEY_x:
case GDK_KEY_equal:
case GDK_KEY_plus:
@@ -506,6 +539,10 @@ key_handler_initial (GtkSourceVimNormal *self,
self->handler = key_handler_split;
break;
+ case GDK_KEY_r:
+ self->handler = key_handler_undo;
+ break;
+
default:
break;
}
@@ -569,6 +606,10 @@ key_handler_initial (GtkSourceVimNormal *self,
self->handler = key_handler_repeat;
break;
+ case GDK_KEY_u:
+ self->handler = key_handler_undo;
+ break;
+
case GDK_KEY_a:
case GDK_KEY_asciitilde:
case GDK_KEY_A:
@@ -582,10 +623,8 @@ key_handler_initial (GtkSourceVimNormal *self,
case GDK_KEY_p:
case GDK_KEY_P:
case GDK_KEY_period:
- case GDK_KEY_R:
case GDK_KEY_s:
case GDK_KEY_S:
- case GDK_KEY_u:
case GDK_KEY_x:
case GDK_KEY_equal:
case GDK_KEY_plus:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]