[gtksourceview/wip/chergert/vim: 145/293] cleanup undo/redo handling




commit d28eee899644252c49e0b049f2758540c0a6f14c
Author: Christian Hergert <chergert redhat com>
Date:   Fri Oct 29 12:40:58 2021 -0700

    cleanup undo/redo handling

 gtksourceview/vim/gtk-source-vim-normal.c | 83 +++++++------------------------
 1 file changed, 17 insertions(+), 66 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-normal.c b/gtksourceview/vim/gtk-source-vim-normal.c
index 3644742f..f88d3f2b 100644
--- a/gtksourceview/vim/gtk-source-vim-normal.c
+++ b/gtksourceview/vim/gtk-source-vim-normal.c
@@ -244,22 +244,6 @@ go_backward_char (GtkSourceVimNormal *self)
                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,
@@ -296,44 +280,6 @@ key_handler_count (GtkSourceVimNormal *self,
        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,
@@ -437,7 +383,7 @@ key_handler_command (GtkSourceVimNormal *self,
                                                            gtk_source_vim_motion_new_none (),
                                                            GTK_SOURCE_VIM_INSERT_HERE,
                                                            NULL);
-                       break;
+                       return TRUE;
 
                case GDK_KEY_J:
                        gtk_source_vim_normal_begin_command (self,
@@ -446,23 +392,31 @@ key_handler_command (GtkSourceVimNormal *self,
                                                             ":join");
                        return TRUE;
 
+               case GDK_KEY_u:
+                       gtk_source_vim_normal_begin_command (self, NULL, NULL, ":undo");
+                       return TRUE;
+
+               case GDK_KEY_r:
+                       if ((mods & GDK_CONTROL_MASK) != 0)
+                       {
+                               gtk_source_vim_normal_begin_command (self, NULL, NULL, ":redo");
+                               return TRUE;
+                       }
+                       break;
+
                case GDK_KEY_asciitilde:
                case GDK_KEY_p:
                case GDK_KEY_P:
                case GDK_KEY_period:
                case GDK_KEY_equal:
                case GDK_KEY_plus:
-                       break;
-
                case GDK_KEY_Y:
                        /* synonum for yy */
-                       break;
-
                default:
-                       return gtk_source_vim_normal_bail (self);
+                       break;
        }
 
-       return TRUE;
+       return gtk_source_vim_normal_bail (self);
 }
 
 static gboolean
@@ -800,7 +754,7 @@ key_handler_initial (GtkSourceVimNormal *self,
                                break;
 
                        case GDK_KEY_r:
-                               self->handler = key_handler_undo;
+                               self->handler = key_handler_command;
                                break;
 
                        default:
@@ -866,10 +820,6 @@ key_handler_initial (GtkSourceVimNormal *self,
                                        self->handler = key_handler_count;
                                break;
 
-                       case GDK_KEY_u:
-                               self->handler = key_handler_undo;
-                               break;
-
                        case GDK_KEY_a:
                        case GDK_KEY_asciitilde:
                        case GDK_KEY_A:
@@ -886,6 +836,7 @@ key_handler_initial (GtkSourceVimNormal *self,
                        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]