[gtksourceview/wip/chergert/vim] clean up undo/redo commands



commit 0a2f927b973a69db2ca0a160b503cfb623ff740a
Author: Christian Hergert <chergert redhat com>
Date:   Fri Oct 29 12:39:55 2021 -0700

    clean up undo/redo commands

 gtksourceview/vim/gtk-source-vim-command.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-command.c b/gtksourceview/vim/gtk-source-vim-command.c
index 770df1c1..f346fc1b 100644
--- a/gtksourceview/vim/gtk-source-vim-command.c
+++ b/gtksourceview/vim/gtk-source-vim-command.c
@@ -85,13 +85,13 @@ gtk_source_vim_command_undo (GtkSourceVimCommand *self)
        buffer = gtk_source_vim_state_get_buffer (GTK_SOURCE_VIM_STATE (self), NULL, NULL);
        count = gtk_source_vim_state_get_count (GTK_SOURCE_VIM_STATE (self));
 
-       for (int i = 0; i < count; i++)
+       do
        {
-               if (gtk_text_buffer_get_can_undo (GTK_TEXT_BUFFER (buffer)))
-               {
-                       gtk_text_buffer_undo (GTK_TEXT_BUFFER (buffer));
-               }
-       }
+               if (!gtk_text_buffer_get_can_undo (GTK_TEXT_BUFFER (buffer)))
+                       break;
+
+               gtk_text_buffer_undo (GTK_TEXT_BUFFER (buffer));
+       } while (--count > 0);
 }
 
 static void
@@ -103,13 +103,13 @@ gtk_source_vim_command_redo (GtkSourceVimCommand *self)
        buffer = gtk_source_vim_state_get_buffer (GTK_SOURCE_VIM_STATE (self), NULL, NULL);
        count = gtk_source_vim_state_get_count (GTK_SOURCE_VIM_STATE (self));
 
-       for (int i = 0; i < count; i++)
+       do
        {
-               if (gtk_text_buffer_get_can_redo (GTK_TEXT_BUFFER (buffer)))
-               {
-                       gtk_text_buffer_redo (GTK_TEXT_BUFFER (buffer));
-               }
-       }
+               if (!gtk_text_buffer_get_can_redo (GTK_TEXT_BUFFER (buffer)))
+                       break;
+
+               gtk_text_buffer_redo (GTK_TEXT_BUFFER (buffer));
+       } while (--count > 0);
 }
 
 static void


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