[gnome-builder/wip/vim] vim: coalesce all changes in insert mode into single undo item.



commit 022913e1efc79e593ab20ea5ea7c13cd75251851
Author: Christian Hergert <christian hergert me>
Date:   Thu Oct 2 00:11:31 2014 -0700

    vim: coalesce all changes in insert mode into single undo item.
    
    This fits closer to how VIM handles the undo stack.

 src/editor/gb-editor-vim.c |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)
---
diff --git a/src/editor/gb-editor-vim.c b/src/editor/gb-editor-vim.c
index 2e385a8..b6aeb48 100644
--- a/src/editor/gb-editor-vim.c
+++ b/src/editor/gb-editor-vim.c
@@ -228,8 +228,32 @@ void
 gb_editor_vim_set_mode (GbEditorVim     *vim,
                         GbEditorVimMode  mode)
 {
+  GtkTextBuffer *buffer;
+
   g_return_if_fail (GB_IS_EDITOR_VIM (vim));
 
+  /*
+   * Ignore if we are already in this mode.
+   */
+  if (mode == vim->priv->mode)
+    return;
+
+  buffer = gtk_text_view_get_buffer (vim->priv->text_view);
+
+  /*
+   * If we are starting insert mode, let's try to coalesce all changes
+   * into one undo stack item like VIM.
+   */
+  if (mode == GB_EDITOR_VIM_INSERT)
+    gtk_text_buffer_begin_user_action (buffer);
+
+  /*
+   * If we are leaving insert mode, let's complete that user action.
+   */
+  if ((mode != GB_EDITOR_VIM_INSERT) &&
+      (vim->priv->mode == GB_EDITOR_VIM_INSERT))
+    gtk_text_buffer_end_user_action (buffer);
+
   vim->priv->mode = mode;
 
   /*


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]