[gnome-builder] vim: fix :0 in command bar



commit e077bf38a1b4b7dcc65e87590a5a77bdd12f79ab
Author: Christian Hergert <christian hergert me>
Date:   Sun Apr 24 14:24:52 2016 -0700

    vim: fix :0 in command bar
    
    0 is not a line number, and so IdeSourceViewMovements had special casing
    to move this to the last line of the buffer. We do want that behavior in
    other places, so special case this in the vim command parser.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=765505

 plugins/command-bar/gb-vim.c |   28 +++++++++++++++++++++++-----
 1 files changed, 23 insertions(+), 5 deletions(-)
---
diff --git a/plugins/command-bar/gb-vim.c b/plugins/command-bar/gb-vim.c
index 9c8c0ef..00bca1a 100644
--- a/plugins/command-bar/gb-vim.c
+++ b/plugins/command-bar/gb-vim.c
@@ -762,10 +762,10 @@ gb_vim_jump_to_line (GtkWidget      *active_widget,
 
   if (IDE_IS_EDITOR_VIEW (active_widget))
     {
+      GtkSourceView  *source_view = GTK_SOURCE_VIEW (IDE_EDITOR_VIEW (active_widget)->frame1->source_view);
       GtkTextBuffer *buffer;
       gboolean extend_selection;
       gint line;
-      GtkSourceView  *source_view = GTK_SOURCE_VIEW (IDE_EDITOR_VIEW (active_widget)->frame1->source_view);
 
       if (!int32_parse (&line, options, 0, G_MAXINT32, "line number", error))
         return FALSE;
@@ -774,10 +774,28 @@ gb_vim_jump_to_line (GtkWidget      *active_widget,
       extend_selection = gtk_text_buffer_get_has_selection (buffer);
       ide_source_view_set_count (IDE_SOURCE_VIEW (source_view), line);
 
-      g_signal_emit_by_name (source_view,
-                             "movement",
-                             IDE_SOURCE_VIEW_MOVEMENT_NTH_LINE,
-                             extend_selection, TRUE, TRUE);
+      if (line == 0)
+        {
+          GtkTextIter iter;
+
+          /*
+           * Zero is not a valid line number, and IdeSourceView treats
+           * that as a move to the end of the buffer. Instead, we want
+           * line 1 to be like vi/vim.
+           */
+          gtk_text_buffer_get_start_iter (buffer, &iter);
+          gtk_text_buffer_select_range (buffer, &iter, &iter);
+          gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (source_view),
+                                        gtk_text_buffer_get_insert (buffer),
+                                        0.0, FALSE, 0.0, 0.0);
+        }
+      else
+        {
+          g_signal_emit_by_name (source_view,
+                                 "movement",
+                                 IDE_SOURCE_VIEW_MOVEMENT_NTH_LINE,
+                                 extend_selection, TRUE, TRUE);
+        }
 
       ide_source_view_set_count (IDE_SOURCE_VIEW (source_view), 0);
 


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