[gtksourceview/wip/chergert/vim: 347/363] implement % for matching ()[]{}




commit f5cc970b3fd70d9cb2e6098f9f4cf13c6dd2f93e
Author: Christian Hergert <chergert redhat com>
Date:   Sun Nov 7 09:24:00 2021 -0800

    implement % for matching ()[]{}

 gtksourceview/vim/gtk-source-vim-motion.c | 51 ++++++++++++++++++++++++++++---
 1 file changed, 47 insertions(+), 4 deletions(-)
---
diff --git a/gtksourceview/vim/gtk-source-vim-motion.c b/gtksourceview/vim/gtk-source-vim-motion.c
index d8a08114..ba3e4d6e 100644
--- a/gtksourceview/vim/gtk-source-vim-motion.c
+++ b/gtksourceview/vim/gtk-source-vim-motion.c
@@ -1513,6 +1513,52 @@ motion_bracket (GtkTextIter        *iter,
        return FALSE;
 }
 
+static gboolean
+motion_matching_char (GtkTextIter        *iter,
+                      GtkSourceVimMotion *self)
+{
+       GtkTextIter orig = *iter;
+       gunichar ch = gtk_text_iter_get_char (iter);
+       gboolean ret;
+
+       switch (ch)
+       {
+               case '(':
+                       ret = gtk_source_vim_iter_forward_block_paren_end (iter);
+                       break;
+
+               case ')':
+                       ret = gtk_source_vim_iter_backward_block_paren_start (iter);
+                       break;
+
+               case '[':
+                       ret = gtk_source_vim_iter_forward_block_bracket_end (iter);
+                       break;
+
+               case ']':
+                       ret = gtk_source_vim_iter_backward_block_bracket_start (iter);
+                       break;
+
+               case '{':
+                       ret = gtk_source_vim_iter_forward_block_brace_end (iter);
+                       break;
+
+               case '}':
+                       ret = gtk_source_vim_iter_backward_block_brace_start (iter);
+                       break;
+
+               default:
+                       /* TODO: check for #if/#ifdef/#elif/#else/#endif */
+                       ret = FALSE;
+                       break;
+       }
+
+       if (!ret)
+               *iter = orig;
+
+       return ret;
+}
+
 static gboolean
 gtk_source_vim_motion_handle_keypress (GtkSourceVimState *state,
                                        guint              keyval,
@@ -1780,10 +1826,7 @@ gtk_source_vim_motion_handle_keypress (GtkSourceVimState *state,
                        return TRUE;
 
                case GDK_KEY_percent:
-                       /* exclusive */
-                       /* charwise */
-                       /* TODO */
-                       G_GNUC_FALLTHROUGH;
+                       return gtk_source_vim_motion_complete (self, motion_matching_char, EXCLUSIVE, 
CHARWISE);
 
                default:
                        return gtk_source_vim_motion_bail (self);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]