[gnome-builder] vim: keep cursor position visible when moving forward/backward
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] vim: keep cursor position visible when moving forward/backward
- Date: Wed, 31 Dec 2014 23:15:43 +0000 (UTC)
commit eb24ac9f52714ade55615e2967fa3ff7015777ae
Author: Christian Hergert <christian hergert me>
Date: Wed Dec 31 15:15:37 2014 -0800
vim: keep cursor position visible when moving forward/backward
src/vim/gb-source-vim.c | 24 ++++++++++++++++++++++++
1 files changed, 24 insertions(+), 0 deletions(-)
---
diff --git a/src/vim/gb-source-vim.c b/src/vim/gb-source-vim.c
index 6338aac..5694d81 100644
--- a/src/vim/gb-source-vim.c
+++ b/src/vim/gb-source-vim.c
@@ -220,6 +220,22 @@ gb_source_vim_new (GtkTextView *text_view)
NULL);
}
+static gboolean
+gb_source_vim_get_iter_visible (GbSourceVim *vim,
+ GtkTextIter *iter)
+{
+ GdkRectangle visible_rect;
+ GdkRectangle iter_location;
+
+ g_return_val_if_fail (GB_IS_SOURCE_VIM (vim), FALSE);
+ g_return_val_if_fail (iter, FALSE);
+
+ gtk_text_view_get_iter_location (vim->priv->text_view, iter, &iter_location);
+ gtk_text_view_get_visible_rect (vim->priv->text_view, &visible_rect);
+
+ return gdk_rectangle_intersect (&visible_rect, &iter_location, NULL);
+}
+
/**
* gb_source_vim_recording_begin:
* @trigger: the character used to trigger recording
@@ -905,6 +921,10 @@ gb_source_vim_move_backward (GbSourceVim *vim)
else
gtk_text_buffer_select_range (buffer, &iter, &iter);
+ if (!gb_source_vim_get_iter_visible (vim, &iter))
+ gtk_text_view_scroll_to_iter (vim->priv->text_view, &iter,
+ 0.0, FALSE, 0.0, 0.0);
+
vim->priv->target_line_offset = gb_source_vim_get_line_offset (vim);
}
}
@@ -1046,6 +1066,10 @@ gb_source_vim_move_forward (GbSourceVim *vim)
else
gtk_text_buffer_select_range (buffer, &iter, &iter);
+ if (!gb_source_vim_get_iter_visible (vim, &iter))
+ gtk_text_view_scroll_to_iter (vim->priv->text_view, &iter,
+ 0.0, FALSE, 0.0, 0.0);
+
vim->priv->target_line_offset = gb_source_vim_get_line_offset (vim);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]