[gnome-builder/wip/libide] libide: add movement to find matching char on current line
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/libide] libide: add movement to find matching char on current line
- Date: Wed, 11 Mar 2015 03:39:06 +0000 (UTC)
commit 7784fdc69a5dff06c5c90661a3fae7ff64a36697
Author: Christian Hergert <christian hergert me>
Date: Tue Mar 10 20:37:39 2015 -0700
libide: add movement to find matching char on current line
This needs a movement char, which can be retrieved using the
IdeSourceview::capture-modifier signal.
libide/ide-source-view-movements.c | 53 ++++++++++++++++++++++++++++++++++++
libide/ide-source-view.h | 3 ++
2 files changed, 56 insertions(+), 0 deletions(-)
---
diff --git a/libide/ide-source-view-movements.c b/libide/ide-source-view-movements.c
index 9495812..86096c1 100644
--- a/libide/ide-source-view-movements.c
+++ b/libide/ide-source-view-movements.c
@@ -1179,6 +1179,49 @@ ide_source_view_movements_next_unmatched (Movement *mv,
g_assert_not_reached ();
}
+static gboolean
+find_match (gunichar ch,
+ gpointer data)
+{
+ Movement *mv = data;
+
+ return (mv->modifier == ch);
+}
+
+static void
+ide_source_view_movements_next_match_modifier (Movement *mv)
+{
+ GtkTextIter insert;
+ GtkTextIter bounds;
+
+ bounds = insert = mv->insert;
+ gtk_text_iter_forward_to_line_end (&bounds);
+
+ if (gtk_text_iter_forward_find_char (&insert, find_match, mv, &bounds))
+ {
+ if (!mv->exclusive)
+ gtk_text_iter_forward_char (&insert);
+ mv->insert = insert;
+ }
+}
+
+static void
+ide_source_view_movements_previous_match_modifier (Movement *mv)
+{
+ GtkTextIter insert;
+ GtkTextIter bounds;
+
+ bounds = insert = mv->insert;
+ gtk_text_iter_set_line_offset (&bounds, 0);
+
+ if (gtk_text_iter_backward_find_char (&insert, find_match, mv, &bounds))
+ {
+ if (!mv->exclusive)
+ gtk_text_iter_forward_char (&insert);
+ mv->insert = insert;
+ }
+}
+
void
_ide_source_view_apply_movement (IdeSourceView *self,
IdeSourceViewMovement movement,
@@ -1425,6 +1468,16 @@ _ide_source_view_apply_movement (IdeSourceView *self,
ide_source_view_movements_next_unmatched (&mv, ')', '(');
break;
+ case IDE_SOURCE_VIEW_MOVEMENT_NEXT_MATCH_MODIFIER:
+ for (i = MAX (1, mv.count); i > 0; i--)
+ ide_source_view_movements_next_match_modifier (&mv);
+ break;
+
+ case IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_MATCH_MODIFIER:
+ for (i = MAX (1, mv.count); i > 0; i--)
+ ide_source_view_movements_previous_match_modifier (&mv);
+ break;
+
default:
g_return_if_reached ();
}
diff --git a/libide/ide-source-view.h b/libide/ide-source-view.h
index ababfda..d887492 100644
--- a/libide/ide-source-view.h
+++ b/libide/ide-source-view.h
@@ -186,6 +186,9 @@ typedef enum
IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_UNMATCHED_PAREN,
IDE_SOURCE_VIEW_MOVEMENT_NEXT_UNMATCHED_PAREN,
+
+ IDE_SOURCE_VIEW_MOVEMENT_NEXT_MATCH_MODIFIER,
+ IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_MATCH_MODIFIER,
} IdeSourceViewMovement;
G_DEFINE_AUTOPTR_CLEANUP_FUNC (IdeSourceView, g_object_unref)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]