[gnome-builder] vim: add simple support for cycling through visible buffers
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] vim: add simple support for cycling through visible buffers
- Date: Wed, 21 Jan 2015 00:55:22 +0000 (UTC)
commit 061198891079667c747cd144b294a52db4856be2
Author: Christian Hergert <christian hergert me>
Date: Tue Jan 20 16:54:27 2015 -0800
vim: add simple support for cycling through visible buffers
Supported movements are:
^w^w
^wn
^wp
We do not currently support moving between the stacked splits, that will
be done in a follow up commit.
https://bugzilla.gnome.org/show_bug.cgi?id=743020
src/documents/gb-document-grid.c | 45 ++++++++++++++++++++++++++++++++++++++
src/editor/gb-editor-view.c | 12 ++++++++++
src/vim/gb-source-vim.c | 15 ++++++++++++
src/vim/gb-source-vim.h | 2 +
4 files changed, 74 insertions(+), 0 deletions(-)
---
diff --git a/src/documents/gb-document-grid.c b/src/documents/gb-document-grid.c
index feb93f2..07ed2db 100644
--- a/src/documents/gb-document-grid.c
+++ b/src/documents/gb-document-grid.c
@@ -177,6 +177,47 @@ gb_document_grid_remove_stack (GbDocumentGrid *grid,
g_list_free (stacks);
}
+static GtkWidget *
+gb_document_grid_get_first_stack (GbDocumentGrid *grid)
+{
+ GtkWidget *child;
+
+ g_return_val_if_fail (GB_IS_DOCUMENT_GRID (grid), NULL);
+
+ child = gtk_bin_get_child (GTK_BIN (grid));
+
+ if (GTK_IS_PANED (child))
+ {
+ child = gtk_paned_get_child1 (GTK_PANED (child));
+ if (GB_IS_DOCUMENT_STACK (child))
+ return child;
+ }
+
+ return NULL;
+}
+
+static GtkWidget *
+gb_document_grid_get_last_stack (GbDocumentGrid *grid)
+{
+ GtkWidget *child;
+ GtkWidget *child2;
+
+ g_return_val_if_fail (GB_IS_DOCUMENT_GRID (grid), NULL);
+
+ child = gtk_bin_get_child (GTK_BIN (grid));
+
+ while (GTK_IS_PANED (child) &&
+ (child2 = gtk_paned_get_child2 (GTK_PANED (child))))
+ child = child2;
+
+ child = gtk_paned_get_child1 (GTK_PANED (child));
+
+ if (GB_IS_DOCUMENT_STACK (child))
+ return child;
+
+ return NULL;
+}
+
static void
gb_document_grid_focus_neighbor (GbDocumentGrid *grid,
GtkDirectionType dir,
@@ -191,10 +232,14 @@ gb_document_grid_focus_neighbor (GbDocumentGrid *grid,
{
case GTK_DIR_LEFT:
neighbor = gb_document_grid_get_stack_before (grid, stack);
+ if (!neighbor)
+ neighbor = gb_document_grid_get_last_stack (grid);
break;
case GTK_DIR_RIGHT:
neighbor = gb_document_grid_get_stack_after (grid, stack);
+ if (!neighbor)
+ neighbor = gb_document_grid_get_first_stack (grid);
break;
default:
diff --git a/src/editor/gb-editor-view.c b/src/editor/gb-editor-view.c
index 07f8ebf..0f61cd1 100644
--- a/src/editor/gb-editor-view.c
+++ b/src/editor/gb-editor-view.c
@@ -668,6 +668,18 @@ gb_editor_view_on_vim_split (GbEditorView *self,
ret = TRUE;
break;
+ case GB_SOURCE_VIM_SPLIT_CYCLE_NEXT:
+ /* TODO: Take our split into account */
+ gb_widget_activate_action (GTK_WIDGET (self), "stack", "focus-right",
+ NULL);
+ break;
+
+ case GB_SOURCE_VIM_SPLIT_CYCLE_PREVIOUS:
+ /* TODO: Take our split into account */
+ gb_widget_activate_action (GTK_WIDGET (self), "stack", "focus-left",
+ NULL);
+ break;
+
case GB_SOURCE_VIM_SPLIT_CLOSE:
if (gb_editor_view_get_split_enabled (self))
{
diff --git a/src/vim/gb-source-vim.c b/src/vim/gb-source-vim.c
index 95ecf56..77d82c7 100644
--- a/src/vim/gb-source-vim.c
+++ b/src/vim/gb-source-vim.c
@@ -3255,6 +3255,19 @@ gb_source_vim_handle_ctrl_w (GbSourceVim *vim,
split = GB_SOURCE_VIM_SPLIT_CLOSE;
break;
+ case GDK_KEY_n:
+ split = GB_SOURCE_VIM_SPLIT_CYCLE_NEXT;
+ break;
+
+ case GDK_KEY_p:
+ split = GB_SOURCE_VIM_SPLIT_CYCLE_PREVIOUS;
+ break;
+
+ case GDK_KEY_w:
+ if ((event->state & GDK_CONTROL_MASK))
+ split = GB_SOURCE_VIM_SPLIT_CYCLE_NEXT;
+ break;
+
default:
break;
}
@@ -5649,6 +5662,8 @@ gb_source_vim_split_get_type (void)
{ GB_SOURCE_VIM_SPLIT_HORIZONTAL, "GB_SOURCE_VIM_SPLIT_HORIZONTAL", "HORIZONTAL" },
{ GB_SOURCE_VIM_SPLIT_VERTICAL, "GB_SOURCE_VIM_SPLIT_VERTICAL", "VERTICAL" },
{ GB_SOURCE_VIM_SPLIT_CLOSE, "GB_SOURCE_VIM_SPLIT_CLOSE", "CLOSE" },
+ { GB_SOURCE_VIM_SPLIT_CYCLE_NEXT, "GB_SOURCE_VIM_SPLIT_CYCLE_NEXT", "CYCLE_NEXT" },
+ { GB_SOURCE_VIM_SPLIT_CYCLE_PREVIOUS, "GB_SOURCE_VIM_SPLIT_CYCLE_PREVIOUS", "CYCLE_PREVIOUS" },
{ 0 }
};
diff --git a/src/vim/gb-source-vim.h b/src/vim/gb-source-vim.h
index d06ce69..c949629 100644
--- a/src/vim/gb-source-vim.h
+++ b/src/vim/gb-source-vim.h
@@ -49,6 +49,8 @@ typedef enum
GB_SOURCE_VIM_SPLIT_HORIZONTAL = 1,
GB_SOURCE_VIM_SPLIT_VERTICAL,
GB_SOURCE_VIM_SPLIT_CLOSE,
+ GB_SOURCE_VIM_SPLIT_CYCLE_NEXT,
+ GB_SOURCE_VIM_SPLIT_CYCLE_PREVIOUS,
} GbSourceVimSplit;
struct _GbSourceVim
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]