[gtksourceview/wip/chergert/vim: 240/363] include \n in yank when necessary




commit 5ddf2e69b1afda8d27931330ce92efa9c69bfdef
Author: Christian Hergert <chergert redhat com>
Date:   Wed Nov 3 11:53:01 2021 -0700

    include \n in yank when necessary

 gtksourceview/vim/gtk-source-vim-command.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-command.c b/gtksourceview/vim/gtk-source-vim-command.c
index e97d8c82..5e3f1695 100644
--- a/gtksourceview/vim/gtk-source-vim-command.c
+++ b/gtksourceview/vim/gtk-source-vim-command.c
@@ -120,27 +120,21 @@ gtk_source_vim_command_yank (GtkSourceVimCommand *self)
 {
        GtkTextIter iter;
        GtkTextIter selection;
-       gboolean needs_newline = FALSE;
        char *text;
 
        gtk_source_vim_state_get_buffer (GTK_SOURCE_VIM_STATE (self), &iter, &selection);
+       text = gtk_text_iter_get_slice (&iter, &selection);
 
        gtk_text_iter_order (&selection, &iter);
 
-       if (gtk_text_iter_ends_line (&iter))
-               gtk_text_iter_forward_char (&iter);
-
        if (gtk_text_iter_is_end (&iter))
-               needs_newline = TRUE;
-
-       text = gtk_text_iter_get_slice (&iter, &selection);
+       {
+               char *tmp = text;
+               text = g_strdup_printf ("%s\n", tmp);
+               g_free (tmp);
+       }
 
-       if (needs_newline)
-               gtk_source_vim_state_set_current_register_value (GTK_SOURCE_VIM_STATE (self),
-                                                                g_strdup_printf ("%s\n", text));
-       else
-               gtk_source_vim_state_set_current_register_value (GTK_SOURCE_VIM_STATE (self),
-                                                                g_steal_pointer (&text));
+       gtk_source_vim_state_set_current_register_value (GTK_SOURCE_VIM_STATE (self), text);
 
        g_free (text);
 }


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