[gnome-builder] vim: Consolidate gb_editor_vim_page_up and down functions
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] vim: Consolidate gb_editor_vim_page_up and down functions
- Date: Sun, 12 Oct 2014 17:29:07 +0000 (UTC)
commit bd6671d20c3667f909ce03c2f2e1a31401d01d01
Author: Hashem Nasarat <hashem riseup net>
Date: Sun Oct 12 12:32:04 2014 -0400
vim: Consolidate gb_editor_vim_page_up and down functions
They use mostly shared code, so there's no reason for the repetition.
https://bugzilla.gnome.org/show_bug.cgi?id=738401
src/editor/gb-editor-vim.c | 73 +++++++++++++++++++++++--------------------
1 files changed, 39 insertions(+), 34 deletions(-)
---
diff --git a/src/editor/gb-editor-vim.c b/src/editor/gb-editor-vim.c
index 30bb41d..9b958a9 100644
--- a/src/editor/gb-editor-vim.c
+++ b/src/editor/gb-editor-vim.c
@@ -93,6 +93,12 @@ struct _GbEditorVimPrivate
typedef enum
{
+ GB_EDITOR_VIM_PAGE_UP,
+ GB_EDITOR_VIM_PAGE_DOWN,
+} GbEditorVimPageDirectionType;
+
+typedef enum
+{
GB_EDITOR_VIM_COMMAND_NOOP,
GB_EDITOR_VIM_COMMAND_MOVEMENT,
GB_EDITOR_VIM_COMMAND_CHANGE,
@@ -2440,54 +2446,53 @@ gb_editor_vim_move_to_iter (GbEditorVim *vim,
}
static void
-gb_editor_vim_page_up (GbEditorVim *vim)
+gb_editor_vim_move_page (GbEditorVim *vim,
+ GbEditorVimPageDirectionType direction)
{
GdkRectangle rect;
- GtkTextIter iter;
+ GtkTextIter iter_top, iter_bottom, iter_current;
guint offset;
gint line;
+ GtkTextBuffer *buffer;
+ gfloat yalign;
g_assert (GB_IS_EDITOR_VIM (vim));
gtk_text_view_get_visible_rect (vim->priv->text_view, &rect);
- gtk_text_view_get_iter_at_location (vim->priv->text_view, &iter,
+ gtk_text_view_get_iter_at_location (vim->priv->text_view, &iter_top,
rect.x, rect.y);
+ gtk_text_view_get_iter_at_location (vim->priv->text_view, &iter_bottom,
+ rect.x, rect.y + rect.height);
- line = MAX (0, gtk_text_iter_get_line (&iter) + SCROLL_OFF);
- gtk_text_iter_set_line (&iter, line);
+ buffer = gtk_text_view_get_buffer (vim->priv->text_view);
+ gtk_text_buffer_get_selection_bounds (buffer, &iter_current, NULL);
- for (offset = vim->priv->target_line_offset; offset; offset--)
- if (gtk_text_iter_ends_line (&iter) || !gtk_text_iter_forward_char (&iter))
+ switch (direction)
+ {
+ case GB_EDITOR_VIM_PAGE_UP:
+ yalign = 1.0;
+ line = MAX (0, gtk_text_iter_get_line (&iter_top) + SCROLL_OFF);
break;
+ case GB_EDITOR_VIM_PAGE_DOWN:
+ yalign = 0.0;
+ /*
+ * rect.y + rect.height is the next line after the end of the buffer so
+ * now we have to decrease one more.
+ */
+ line = MAX (0, gtk_text_iter_get_line (&iter_bottom) - SCROLL_OFF - 1);
+ break;
+ default:
+ g_assert_not_reached();
+ }
- gb_editor_vim_move_to_iter (vim, &iter, 1.0);
-}
-
-static void
-gb_editor_vim_page_down (GbEditorVim *vim)
-{
- GdkRectangle rect;
- GtkTextIter iter;
- guint offset;
- gint line;
-
- g_assert (GB_IS_EDITOR_VIM (vim));
-
- gtk_text_view_get_visible_rect (vim->priv->text_view, &rect);
- gtk_text_view_get_iter_at_location (vim->priv->text_view, &iter,
- rect.x, rect.y + rect.height);
-
- /*
- * rect.y + rect.height is the next line after the end of the buffer so
- * now we have to decrease one more.
- */
- line = MAX (0, gtk_text_iter_get_line (&iter) - SCROLL_OFF - 1);
- gtk_text_iter_set_line (&iter, line);
+ gtk_text_iter_set_line (&iter_current, line);
for (offset = vim->priv->target_line_offset; offset; offset--)
- if (gtk_text_iter_ends_line (&iter) || !gtk_text_iter_forward_char (&iter))
+ if (gtk_text_iter_ends_line (&iter_current) ||
+ !gtk_text_iter_forward_char (&iter_current))
break;
- gb_editor_vim_move_to_iter (vim, &iter, 0.0);
+
+ gb_editor_vim_move_to_iter (vim, &iter_current, yalign);
}
static void
@@ -2736,7 +2741,7 @@ gb_editor_vim_handle_normal (GbEditorVim *vim,
if ((event->state & GDK_CONTROL_MASK) != 0)
{
gb_editor_vim_clear_phrase (vim);
- gb_editor_vim_page_up (vim);
+ gb_editor_vim_move_page (vim, GB_EDITOR_VIM_PAGE_UP);
return TRUE;
}
break;
@@ -2745,7 +2750,7 @@ gb_editor_vim_handle_normal (GbEditorVim *vim,
if ((event->state & GDK_CONTROL_MASK) != 0)
{
gb_editor_vim_clear_phrase (vim);
- gb_editor_vim_page_down (vim);
+ gb_editor_vim_move_page (vim, GB_EDITOR_VIM_PAGE_DOWN);
return TRUE;
}
break;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]