[gtksourceview/wip/chergert/vim] implement [{ [( ]} ])
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/vim] implement [{ [( ]} ])
- Date: Sun, 7 Nov 2021 16:55:03 +0000 (UTC)
commit 9f8da936cc66412ea21cf3038f2d0813a4a8fa21
Author: Christian Hergert <chergert redhat com>
Date: Sun Nov 7 08:53:37 2021 -0800
implement [{ [( ]} ])
gtksourceview/vim/gtk-source-vim-motion.c | 64 +++++++++++++++++++++++++++++++
gtksourceview/vim/gtk-source-vim-normal.c | 2 +
2 files changed, 66 insertions(+)
---
diff --git a/gtksourceview/vim/gtk-source-vim-motion.c b/gtksourceview/vim/gtk-source-vim-motion.c
index 96230afe..c4e5c78a 100644
--- a/gtksourceview/vim/gtk-source-vim-motion.c
+++ b/gtksourceview/vim/gtk-source-vim-motion.c
@@ -88,6 +88,10 @@ struct _GtkSourceVimMotion
/* If the command starts with `g` such as `ge` or `gE`. */
guint g_command : 1;
+ /* If we're in a [( or ]} type motion */
+ guint bracket_right : 1;
+ guint bracket_left : 1;
+
/* If we called gtk_source_vim_motion_bail(). */
guint failed : 1;
@@ -1467,6 +1471,30 @@ gtk_source_vim_motion_begin_char_pending (GtkSourceVimMotion *self,
return TRUE;
}
+static gboolean
+motion_bracket (GtkTextIter *iter,
+ GtkSourceVimMotion *self)
+{
+ if (self->bracket_left)
+ {
+ if (self->f_char == '(')
+ return gtk_source_vim_iter_backward_block_paren_start (iter);
+
+ if (self->f_char == '{')
+ return gtk_source_vim_iter_backward_block_brace_start (iter);
+ }
+ else
+ {
+ if (self->f_char == ')')
+ return gtk_source_vim_iter_forward_block_paren_end (iter);
+
+ if (self->f_char == '}')
+ return gtk_source_vim_iter_forward_block_brace_end (iter);
+ }
+
+ return FALSE;
+}
+
static gboolean
gtk_source_vim_motion_handle_keypress (GtkSourceVimState *state,
guint keyval,
@@ -1514,6 +1542,34 @@ gtk_source_vim_motion_handle_keypress (GtkSourceVimState *state,
g_assert_not_reached ();
}
+ if (self->bracket_left || self->bracket_right)
+ {
+ switch (keyval)
+ {
+ case GDK_KEY_parenleft:
+ self->f_char = '(';
+ return gtk_source_vim_motion_complete (self, motion_bracket, INCLUSIVE,
CHARWISE);
+
+ case GDK_KEY_parenright:
+ self->f_char = ')';
+ return gtk_source_vim_motion_complete (self, motion_bracket, INCLUSIVE,
CHARWISE);
+
+ case GDK_KEY_braceleft:
+ self->f_char = '{';
+ return gtk_source_vim_motion_complete (self, motion_bracket, INCLUSIVE,
CHARWISE);
+
+ case GDK_KEY_braceright:
+ self->f_char = '}';
+ return gtk_source_vim_motion_complete (self, motion_bracket, INCLUSIVE,
CHARWISE);
+
+ case GDK_KEY_M:
+ case GDK_KEY_m:
+ /* TODO: support next method */
+ default:
+ break;
+ }
+ }
+
if (gtk_source_vim_state_get_count_set (state) && get_number (keyval, &n))
{
count = count * 10 + n;
@@ -1697,6 +1753,14 @@ gtk_source_vim_motion_handle_keypress (GtkSourceVimState *state,
else
return gtk_source_vim_motion_complete (self, motion_prev_search, INCLUSIVE,
CHARWISE);
+ case GDK_KEY_bracketleft:
+ self->bracket_left = TRUE;
+ return TRUE;
+
+ case GDK_KEY_bracketright:
+ self->bracket_right = TRUE;
+ return TRUE;
+
case GDK_KEY_percent:
/* exclusive */
/* charwise */
diff --git a/gtksourceview/vim/gtk-source-vim-normal.c b/gtksourceview/vim/gtk-source-vim-normal.c
index 33c380a0..2172c40b 100644
--- a/gtksourceview/vim/gtk-source-vim-normal.c
+++ b/gtksourceview/vim/gtk-source-vim-normal.c
@@ -1080,6 +1080,8 @@ key_handler_initial (GtkSourceVimNormal *self,
case GDK_KEY_BackSpace:
case GDK_KEY_braceleft:
case GDK_KEY_braceright:
+ case GDK_KEY_bracketleft:
+ case GDK_KEY_bracketright:
case GDK_KEY_dollar:
case GDK_KEY_Down:
case GDK_KEY_e:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]