[gnome-builder] vim: add special case for 'yy' on last line of buffer
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] vim: add special case for 'yy' on last line of buffer
- Date: Sat, 13 Dec 2014 03:48:53 +0000 (UTC)
commit 2bca4f08082e2b0db2998288b7ae5f8eb6ba4d00
Author: Christian Hergert <christian hergert me>
Date: Fri Dec 12 19:48:45 2014 -0800
vim: add special case for 'yy' on last line of buffer
We need to handle this specially because GtkTextBuffer/GtkTextView does
not give us a \n at the end.
src/vim/gb-source-vim.c | 55 ++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 50 insertions(+), 5 deletions(-)
---
diff --git a/src/vim/gb-source-vim.c b/src/vim/gb-source-vim.c
index 2278efe..34c6d97 100644
--- a/src/vim/gb-source-vim.c
+++ b/src/vim/gb-source-vim.c
@@ -2177,13 +2177,26 @@ gb_source_vim_move_to_end (GbSourceVim *vim)
}
static void
+gb_source_vim_set_clipboard_text (GbSourceVim *vim,
+ const gchar *text)
+{
+ GtkClipboard *clipboard;
+
+ g_return_if_fail (GB_IS_SOURCE_VIM (vim));
+ g_return_if_fail (text);
+
+ clipboard = gtk_widget_get_clipboard (GTK_WIDGET (vim->priv->text_view),
+ GDK_SELECTION_CLIPBOARD);
+ gtk_clipboard_set_text (clipboard, text, -1);
+}
+
+static void
gb_source_vim_yank (GbSourceVim *vim)
{
GtkTextBuffer *buffer;
GtkTextMark *insert;
GtkTextIter begin;
GtkTextIter end;
- GtkClipboard *clipboard;
gchar *text;
g_assert (GB_IS_SOURCE_VIM (vim));
@@ -2227,9 +2240,7 @@ gb_source_vim_yank (GbSourceVim *vim)
/*
* Update the selection clipboard.
*/
- clipboard = gtk_widget_get_clipboard (GTK_WIDGET (vim->priv->text_view),
- GDK_SELECTION_CLIPBOARD);
- gtk_clipboard_set_text (clipboard, text, -1);
+ gb_source_vim_set_clipboard_text (vim, text);
g_free (text);
/*
@@ -4408,12 +4419,46 @@ gb_source_vim_cmd_yank (GbSourceVim *vim,
if (!gtk_text_buffer_get_has_selection (buffer))
{
if (modifier == 'y')
- gb_source_vim_cmd_select_line (vim, count, '\0');
+ {
+ GtkTextIter iter;
+ GtkTextMark *insert;
+
+ insert = gtk_text_buffer_get_insert (buffer);
+ gtk_text_buffer_get_iter_at_mark (buffer, &iter, insert);
+
+ if (!gtk_text_iter_forward_to_line_end (&iter))
+ {
+ GtkTextIter begin = iter;
+ gchar *str;
+ gchar *line;
+
+ /*
+ * WORKAROUND:
+ *
+ * We are on the last line of the file, so we can't fetch the
+ * newline at the end of this line. We will need to synthesize
+ * the line with our own trailing\n, so that the yank does not
+ * include a prefixing newline.
+ */
+ gtk_text_iter_set_line_offset (&begin, 0);
+ str = gtk_text_iter_get_slice (&begin, &iter);
+ line = g_strdup_printf ("%s\n", str);
+ gb_source_vim_set_clipboard_text (vim, line);
+ g_free (str);
+ g_free (line);
+
+ goto finish;
+ }
+
+ gb_source_vim_cmd_select_line (vim, count, '\0');
+ }
else
gb_source_vim_apply_motion (vim, modifier, count);
}
gb_source_vim_yank (vim);
+
+finish:
gb_source_vim_clear_selection (vim);
gb_source_vim_restore_position (vim);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]