[gnome-builder/wip/chergert/perspective] source-view: avoid external jumps when possible



commit 575203cf644564bcf44fc72b8b5547698f4f0b8e
Author: Christian Hergert <chergert redhat com>
Date:   Sat Dec 5 23:13:23 2015 -0800

    source-view: avoid external jumps when possible

 libide/ide-source-view.c |   21 +++++++++++++++++++--
 1 files changed, 19 insertions(+), 2 deletions(-)
---
diff --git a/libide/ide-source-view.c b/libide/ide-source-view.c
index 7f2ac7c..91d6d33 100644
--- a/libide/ide-source-view.c
+++ b/libide/ide-source-view.c
@@ -4318,9 +4318,9 @@ ide_source_view_goto_definition_symbol_cb (GObject      *object,
                                            GAsyncResult *result,
                                            gpointer      user_data)
 {
-  IdeBuffer *buffer = (IdeBuffer *)object;
   g_autoptr(IdeSourceView) self = user_data;
   g_autoptr(IdeSymbol) symbol = NULL;
+  IdeBuffer *buffer = (IdeBuffer *)object;
   g_autoptr(GError) error = NULL;
   IdeSourceLocation *srcloc;
 
@@ -4339,10 +4339,12 @@ ide_source_view_goto_definition_symbol_cb (GObject      *object,
 
   if (srcloc != NULL)
     {
-#ifdef IDE_ENABLE_TRACE
       guint line = ide_source_location_get_line (srcloc);
       guint line_offset = ide_source_location_get_line_offset (srcloc);
       IdeFile *file = ide_source_location_get_file (srcloc);
+      IdeFile *our_file = ide_buffer_get_file (buffer);
+
+#ifdef IDE_ENABLE_TRACE
       const gchar *filename = ide_file_get_path (file);
 
       IDE_TRACE_MSG ("%s => %s +%u:%u",
@@ -4350,6 +4352,21 @@ ide_source_view_goto_definition_symbol_cb (GObject      *object,
                      filename, line+1, line_offset+1);
 #endif
 
+      /*
+       * If we are navigating within this file, just stay captive instead of
+       * potentially allowing jumping to the file in another editor.
+       */
+      if (ide_file_equal (file, our_file))
+        {
+          GtkTextIter iter;
+
+          gtk_text_buffer_get_iter_at_line_offset (GTK_TEXT_BUFFER (buffer),
+                                                   &iter, line, line_offset);
+          gtk_text_buffer_select_range (GTK_TEXT_BUFFER (buffer), &iter, &iter);
+          ide_source_view_scroll_to_insert (self);
+          return;
+        }
+
       g_signal_emit (self, signals [FOCUS_LOCATION], 0, srcloc);
     }
 }


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