[gnome-builder/wip/chergert/layout: 78/118] editor: fix focus_location() from editor perspective



commit 2661550c770767cf1b28a4caa814f013805b2e29
Author: Christian Hergert <chergert redhat com>
Date:   Sun Jul 2 21:17:08 2017 -0700

    editor: fix focus_location() from editor perspective
    
    When refocusing after the movement, it would immediately go back
    to the previous position.

 libide/editor/ide-editor-perspective.c |    1 -
 libide/editor/ide-editor-view.c        |    8 ++++++--
 2 files changed, 6 insertions(+), 3 deletions(-)
---
diff --git a/libide/editor/ide-editor-perspective.c b/libide/editor/ide-editor-perspective.c
index 1fabdf5..4c862c7 100644
--- a/libide/editor/ide-editor-perspective.c
+++ b/libide/editor/ide-editor-perspective.c
@@ -234,7 +234,6 @@ ide_editor_perspective_focus_location_full (IdeEditorPerspective *self,
   stack = gtk_widget_get_ancestor (GTK_WIDGET (lookup.view), IDE_TYPE_LAYOUT_STACK);
   ide_layout_stack_set_visible_child (IDE_LAYOUT_STACK (stack), IDE_LAYOUT_VIEW (lookup.view));
   ide_editor_view_scroll_to_line (lookup.view, line);
-  gtk_widget_grab_focus (GTK_WIDGET (lookup.view));
 }
 
 void
diff --git a/libide/editor/ide-editor-view.c b/libide/editor/ide-editor-view.c
index 720e268..03f451d 100644
--- a/libide/editor/ide-editor-view.c
+++ b/libide/editor/ide-editor-view.c
@@ -711,8 +711,10 @@ ide_editor_view_get_language_id (IdeEditorView *self)
  * ide_editor_view_scroll_to_line:
  * @self: a #IdeEditorView
  *
- * This is a helper to quickly jump to a given line without all the
- * frills.
+ * This is a helper to quickly jump to a given line without all the frills. It
+ * will also ensure focus on the editor view, so that refocusing the view
+ * afterwards does not cause the view to restore the cursor to the previous
+ * location.
  */
 void
 ide_editor_view_scroll_to_line (IdeEditorView *self,
@@ -724,6 +726,8 @@ ide_editor_view_scroll_to_line (IdeEditorView *self,
   g_return_if_fail (self->buffer != NULL);
   g_return_if_fail (line <= G_MAXINT);
 
+  gtk_widget_grab_focus (GTK_WIDGET (self->source_view));
+
   gtk_text_buffer_get_iter_at_line (GTK_TEXT_BUFFER (self->buffer), &iter, line);
   gtk_text_buffer_select_range (GTK_TEXT_BUFFER (self->buffer), &iter, &iter);
   ide_source_view_scroll_to_insert (self->source_view);


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