[gnome-builder] editor: implement VIM style movement keys.
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] editor: implement VIM style movement keys.
- Date: Thu, 25 Sep 2014 23:40:41 +0000 (UTC)
commit 9d51eb70673b516c1701d0ac58cdf80d1b2fe588
Author: Christian Hergert <christian hergert me>
Date: Thu Sep 25 16:37:22 2014 -0700
editor: implement VIM style movement keys.
Not perfect, but at least it's something. You can move up/down/left/right
in the normal fashion, except that you need <Alt>. This does not implement
things as a command stack like VIM does, meaning you can't combine them
with numbers.
Additionally, another annoyance to fix is that it looses the line offset
when you move to a shorter line. We need to plumb through storage of the
original offset when we truncate and fail to get to the same offset.
src/editor/gb-editor-commands.c | 115 +++++++++++++++++++++++++++++++++
src/resources/keybindings/default.ini | 4 +
2 files changed, 119 insertions(+), 0 deletions(-)
---
diff --git a/src/editor/gb-editor-commands.c b/src/editor/gb-editor-commands.c
index f6a8784..e71df5d 100644
--- a/src/editor/gb-editor-commands.c
+++ b/src/editor/gb-editor-commands.c
@@ -917,6 +917,117 @@ gb_editor_commands_scroll_up (GbEditorWorkspace *workspace,
}
static void
+gb_editor_commands_move_forward (GbEditorWorkspace *workspace,
+ GbEditorTab *tab)
+{
+ GtkTextBuffer *buffer;
+ GtkTextIter iter;
+ GtkTextMark *insert;
+
+ g_return_if_fail (GB_IS_EDITOR_WORKSPACE (workspace));
+ g_return_if_fail (GB_IS_EDITOR_TAB (tab));
+
+ buffer = GTK_TEXT_BUFFER (tab->priv->document);
+ insert = gtk_text_buffer_get_insert (buffer);
+ gtk_text_buffer_get_iter_at_mark (buffer, &iter, insert);
+
+ if (!gtk_text_iter_ends_line (&iter) && gtk_text_iter_forward_char (&iter))
+ gtk_text_buffer_select_range (buffer, &iter, &iter);
+}
+
+static void
+gb_editor_commands_move_backward (GbEditorWorkspace *workspace,
+ GbEditorTab *tab)
+{
+ GtkTextBuffer *buffer;
+ GtkTextIter iter;
+ GtkTextMark *insert;
+
+ g_return_if_fail (GB_IS_EDITOR_WORKSPACE (workspace));
+ g_return_if_fail (GB_IS_EDITOR_TAB (tab));
+
+ buffer = GTK_TEXT_BUFFER (tab->priv->document);
+ insert = gtk_text_buffer_get_insert (buffer);
+ gtk_text_buffer_get_iter_at_mark (buffer, &iter, insert);
+
+ if (!gtk_text_iter_starts_line (&iter) && gtk_text_iter_backward_char (&iter))
+ gtk_text_buffer_select_range (buffer, &iter, &iter);
+
+ gtk_text_view_scroll_mark_onscreen (GTK_TEXT_VIEW (tab->priv->source_view),
+ insert);
+}
+
+static void
+gb_editor_commands_move_up (GbEditorWorkspace *workspace,
+ GbEditorTab *tab)
+{
+ GtkTextBuffer *buffer;
+ GtkTextIter iter;
+ GtkTextMark *insert;
+ guint line;
+ guint line_offset;
+ guint i;
+
+ g_return_if_fail (GB_IS_EDITOR_WORKSPACE (workspace));
+ g_return_if_fail (GB_IS_EDITOR_TAB (tab));
+
+ buffer = GTK_TEXT_BUFFER (tab->priv->document);
+ insert = gtk_text_buffer_get_insert (buffer);
+ gtk_text_buffer_get_iter_at_mark (buffer, &iter, insert);
+
+ line = gtk_text_iter_get_line (&iter);
+ line_offset = gtk_text_iter_get_line_offset (&iter);
+
+ if (line == 0)
+ return;
+
+ gtk_text_buffer_get_iter_at_line (buffer, &iter, line - 1);
+ for (i = 0; i < line_offset; i++)
+ if (gtk_text_iter_ends_line (&iter) ||
+ !gtk_text_iter_forward_char (&iter))
+ break;
+
+ gtk_text_buffer_select_range (buffer, &iter, &iter);
+
+ gtk_text_view_scroll_mark_onscreen (GTK_TEXT_VIEW (tab->priv->source_view),
+ insert);
+}
+
+static void
+gb_editor_commands_move_down (GbEditorWorkspace *workspace,
+ GbEditorTab *tab)
+{
+ GtkTextBuffer *buffer;
+ GtkTextIter iter;
+ GtkTextMark *insert;
+ guint line;
+ guint line_offset;
+ guint i;
+
+ g_return_if_fail (GB_IS_EDITOR_WORKSPACE (workspace));
+ g_return_if_fail (GB_IS_EDITOR_TAB (tab));
+
+ buffer = GTK_TEXT_BUFFER (tab->priv->document);
+ insert = gtk_text_buffer_get_insert (buffer);
+ gtk_text_buffer_get_iter_at_mark (buffer, &iter, insert);
+
+ line = gtk_text_iter_get_line (&iter);
+ line_offset = gtk_text_iter_get_line_offset (&iter);
+
+ gtk_text_buffer_get_iter_at_line (buffer, &iter, line + 1);
+ if (gtk_text_iter_get_line (&iter) == (line + 1))
+ for (i = 0; i < line_offset; i++)
+ if (gtk_text_iter_ends_line (&iter) ||
+ !gtk_text_iter_forward_char (&iter))
+ break;
+
+ gtk_text_buffer_select_range (buffer, &iter, &iter);
+
+ gtk_text_view_scroll_mark_onscreen (GTK_TEXT_VIEW (tab->priv->source_view),
+ insert);
+}
+
+static void
gb_editor_commands_highlight_mode (GSimpleAction *action,
GVariant *parameter,
GbEditorWorkspace *workspace)
@@ -1001,6 +1112,10 @@ gb_editor_commands_init (GbEditorWorkspace *workspace)
{ "trim-trailing-space", gb_editor_commands_trim_trailing_space, TRUE },
{ "scroll-down", gb_editor_commands_scroll_down, TRUE },
{ "scroll-up", gb_editor_commands_scroll_up, TRUE },
+ { "move-forward", gb_editor_commands_move_forward, TRUE },
+ { "move-backward", gb_editor_commands_move_backward, TRUE },
+ { "move-up", gb_editor_commands_move_up, TRUE },
+ { "move-down", gb_editor_commands_move_down, TRUE },
{ NULL }
};
GSimpleAction *action;
diff --git a/src/resources/keybindings/default.ini b/src/resources/keybindings/default.ini
index d4b4985..8e1466b 100644
--- a/src/resources/keybindings/default.ini
+++ b/src/resources/keybindings/default.ini
@@ -25,3 +25,7 @@ toggle-preview = <Control><Alt>P
select-line = <Control>L
scroll-up = <Control>Y
scroll-down = <Control>E
+move-up = <Alt>K
+move-down = <Alt>J
+move-forward = <Alt>L
+move-backward = <Alt>H
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]