[gtksourceview/wip/chergert/vim: 157/293] implement P for paste before line
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/vim: 157/293] implement P for paste before line
- Date: Fri, 5 Nov 2021 04:23:02 +0000 (UTC)
commit ed0cc728ef08cdf428c058531db0e93e089b0b50
Author: Christian Hergert <chergert redhat com>
Date: Fri Oct 29 15:57:16 2021 -0700
implement P for paste before line
gtksourceview/vim/gtk-source-vim-command.c | 61 ++++++++++++++++++++++++++----
gtksourceview/vim/gtk-source-vim-normal.c | 5 ++-
2 files changed, 57 insertions(+), 9 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-command.c b/gtksourceview/vim/gtk-source-vim-command.c
index 5732ea49..4428842f 100644
--- a/gtksourceview/vim/gtk-source-vim-command.c
+++ b/gtksourceview/vim/gtk-source-vim-command.c
@@ -170,6 +170,50 @@ gtk_source_vim_command_paste_after (GtkSourceVimCommand *self)
gtk_source_vim_state_end_user_action (GTK_SOURCE_VIM_STATE (self));
}
+static void
+gtk_source_vim_command_paste_before (GtkSourceVimCommand *self)
+{
+ GtkSourceVimState *registers;
+ GtkSourceBuffer *buffer;
+ GtkTextIter iter;
+ GtkTextIter selection;
+ const char *text;
+ int count;
+
+ buffer = gtk_source_vim_state_get_buffer (GTK_SOURCE_VIM_STATE (self), &iter, &selection);
+ registers = gtk_source_vim_state_get_registers (GTK_SOURCE_VIM_STATE (self));
+ text = gtk_source_vim_registers_get (GTK_SOURCE_VIM_REGISTERS (registers), NULL);
+ count = gtk_source_vim_state_get_count (GTK_SOURCE_VIM_STATE (self));
+
+ if (text == NULL)
+ {
+ return;
+ }
+
+ gtk_text_iter_order (&selection, &iter);
+
+ gtk_source_vim_state_begin_user_action (GTK_SOURCE_VIM_STATE (self));
+
+ /* If there is a \n, this is a linewise paste */
+ if (g_str_has_suffix (text, "\n"))
+ {
+ do
+ {
+ gtk_text_iter_set_line_offset (&iter, 0);
+ gtk_text_buffer_insert (GTK_TEXT_BUFFER (buffer), &iter, text, -1);
+ } while (--count > 0);
+ }
+ else
+ {
+ do
+ {
+ gtk_text_buffer_insert (GTK_TEXT_BUFFER (buffer), &iter, text, -1);
+ } while (--count > 0);
+ }
+
+ gtk_source_vim_state_end_user_action (GTK_SOURCE_VIM_STATE (self));
+}
+
static void
gtk_source_vim_command_undo (GtkSourceVimCommand *self)
{
@@ -381,14 +425,15 @@ gtk_source_vim_command_class_init (GtkSourceVimCommandClass *klass)
#define ADD_COMMAND(name, func) \
g_hash_table_insert(commands, (char*)name, (gpointer)func)
- ADD_COMMAND (":join", gtk_source_vim_command_join);
- ADD_COMMAND (":j", gtk_source_vim_command_join);
- ADD_COMMAND (":undo", gtk_source_vim_command_undo);
- ADD_COMMAND (":u", gtk_source_vim_command_undo);
- ADD_COMMAND (":redo", gtk_source_vim_command_redo);
- ADD_COMMAND (":yank", gtk_source_vim_command_yank);
- ADD_COMMAND (":y", gtk_source_vim_command_yank);
- ADD_COMMAND (":_paste_after", gtk_source_vim_command_paste_after);
+ ADD_COMMAND (":join", gtk_source_vim_command_join);
+ ADD_COMMAND (":j", gtk_source_vim_command_join);
+ ADD_COMMAND (":undo", gtk_source_vim_command_undo);
+ ADD_COMMAND (":u", gtk_source_vim_command_undo);
+ ADD_COMMAND (":redo", gtk_source_vim_command_redo);
+ ADD_COMMAND (":yank", gtk_source_vim_command_yank);
+ ADD_COMMAND (":y", gtk_source_vim_command_yank);
+ ADD_COMMAND (":_paste_after", gtk_source_vim_command_paste_after);
+ ADD_COMMAND (":_paste_before", gtk_source_vim_command_paste_before);
#undef ADD_COMMAND
}
diff --git a/gtksourceview/vim/gtk-source-vim-normal.c b/gtksourceview/vim/gtk-source-vim-normal.c
index 18133c34..15c5a91f 100644
--- a/gtksourceview/vim/gtk-source-vim-normal.c
+++ b/gtksourceview/vim/gtk-source-vim-normal.c
@@ -420,8 +420,11 @@ key_handler_command (GtkSourceVimNormal *self,
gtk_source_vim_normal_begin_command (self, NULL, NULL, ":_paste_after");
return TRUE;
- case GDK_KEY_asciitilde:
case GDK_KEY_P:
+ gtk_source_vim_normal_begin_command (self, NULL, NULL, ":_paste_before");
+ return TRUE;
+
+ case GDK_KEY_asciitilde:
case GDK_KEY_equal:
case GDK_KEY_plus:
default:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]