[gnome-builder] buffer: add helpers to avoid stomping on cursor placement
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] buffer: add helpers to avoid stomping on cursor placement
- Date: Wed, 19 Jul 2017 11:03:14 +0000 (UTC)
commit 866d28e41e6efec7fb7738dd1c7365a91e2a09bb
Author: Christian Hergert <chergert redhat com>
Date: Fri Jun 30 17:30:09 2017 -0700
buffer: add helpers to avoid stomping on cursor placement
This can be useful so that we don't restore the cursor mark
after something has internally tried to set it.
libide/buffers/ide-buffer-manager.c | 11 +++++++----
libide/buffers/ide-buffer.c | 17 +++++++++++++++++
libide/ide-internal.h | 2 ++
3 files changed, 26 insertions(+), 4 deletions(-)
---
diff --git a/libide/buffers/ide-buffer-manager.c b/libide/buffers/ide-buffer-manager.c
index 8a154a7..0d14d96 100644
--- a/libide/buffers/ide-buffer-manager.c
+++ b/libide/buffers/ide-buffer-manager.c
@@ -602,10 +602,13 @@ ide_buffer_manager_load_file__load_cb (GObject *object,
else
gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (state->buffer), &iter);
- IDE_TRACE_MSG ("Restoring insert mark to %u:%u",
- gtk_text_iter_get_line (&iter) + 1,
- gtk_text_iter_get_line_offset (&iter) + 1);
- gtk_text_buffer_select_range (GTK_TEXT_BUFFER (state->buffer), &iter, &iter);
+ if (_ide_buffer_can_restore_cursor (state->buffer))
+ {
+ IDE_TRACE_MSG ("Restoring insert mark to %u:%u",
+ gtk_text_iter_get_line (&iter) + 1,
+ gtk_text_iter_get_line_offset (&iter) + 1);
+ gtk_text_buffer_select_range (GTK_TEXT_BUFFER (state->buffer), &iter, &iter);
+ }
/*
* Try to discover the content type more accurately now that we have access to the
diff --git a/libide/buffers/ide-buffer.c b/libide/buffers/ide-buffer.c
index a96e1cf..d0592f9 100644
--- a/libide/buffers/ide-buffer.c
+++ b/libide/buffers/ide-buffer.c
@@ -100,6 +100,7 @@ typedef struct
gsize change_count;
+ guint cancel_cursor_restore : 1;
guint changed_on_volume : 1;
guint highlight_diagnostics : 1;
guint loading : 1;
@@ -2937,3 +2938,19 @@ ide_buffer_format_selection_finish (IdeBuffer *self,
IDE_RETURN (ret);
}
+
+void
+_ide_buffer_cancel_cursor_restore (IdeBuffer *self)
+{
+ IdeBufferPrivate *priv = ide_buffer_get_instance_private (self);
+ g_return_if_fail (IDE_IS_BUFFER (self));
+ priv->cancel_cursor_restore = TRUE;
+}
+
+gboolean
+_ide_buffer_can_restore_cursor (IdeBuffer *self)
+{
+ IdeBufferPrivate *priv = ide_buffer_get_instance_private (self);
+ g_return_val_if_fail (IDE_IS_BUFFER (self), FALSE);
+ return !priv->cancel_cursor_restore;
+}
diff --git a/libide/ide-internal.h b/libide/ide-internal.h
index 6dd1705..e2b991e 100644
--- a/libide/ide-internal.h
+++ b/libide/ide-internal.h
@@ -40,6 +40,8 @@ void _ide_buffer_set_changed_on_volume (IdeBuffer
gboolean _ide_buffer_get_loading (IdeBuffer *self);
void _ide_buffer_set_loading (IdeBuffer *self,
gboolean loading);
+void _ide_buffer_cancel_cursor_restore (IdeBuffer *self);
+gboolean _ide_buffer_can_restore_cursor (IdeBuffer *self);
void _ide_buffer_set_mtime (IdeBuffer *self,
const GTimeVal *mtime);
void _ide_buffer_set_read_only (IdeBuffer *buffer,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]