[gnome-builder/wip/vim] vim: make paste (p) place the cursor on the first pasted line.
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/vim] vim: make paste (p) place the cursor on the first pasted line.
- Date: Tue, 30 Sep 2014 23:52:44 +0000 (UTC)
commit 4e04f9b521fc5cee915b721a9f1d9c9172732931
Author: Christian Hergert <christian hergert me>
Date: Tue Sep 30 16:52:38 2014 -0700
vim: make paste (p) place the cursor on the first pasted line.
src/editor/gb-editor-vim.c | 21 +++++++++++++++++++++
1 files changed, 21 insertions(+), 0 deletions(-)
---
diff --git a/src/editor/gb-editor-vim.c b/src/editor/gb-editor-vim.c
index 266482f..18896b2 100644
--- a/src/editor/gb-editor-vim.c
+++ b/src/editor/gb-editor-vim.c
@@ -967,12 +967,24 @@ gb_editor_vim_paste (GbEditorVim *vim)
{
GtkClipboard *clipboard;
GtkTextBuffer *buffer;
+ GtkTextMark *insert;
+ GtkTextIter iter;
+ guint line;
+ guint offset;
gchar *text;
g_return_if_fail (GB_IS_EDITOR_VIM (vim));
buffer = gtk_text_view_get_buffer (vim->priv->text_view);
+ /*
+ * Track the current insert location so we can jump back to it.
+ */
+ insert = gtk_text_buffer_get_insert (buffer);
+ gtk_text_buffer_get_iter_at_mark (buffer, &iter, insert);
+ line = gtk_text_iter_get_line (&iter);
+ offset = gtk_text_iter_get_line_offset (&iter);
+
gtk_text_buffer_begin_user_action (buffer);
/*
@@ -1031,6 +1043,15 @@ gb_editor_vim_paste (GbEditorVim *vim)
gtk_text_buffer_end_user_action (buffer);
+ /*
+ * Restore the cursor position.
+ */
+ gtk_text_buffer_get_iter_at_line (buffer, &iter, line + 1);
+ for (; offset; offset--)
+ if (gtk_text_iter_ends_line (&iter) || !gtk_text_iter_forward_char (&iter))
+ break;
+ gtk_text_buffer_select_range (buffer, &iter, &iter);
+
g_free (text);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]