[gnome-builder/wip/libide] libide: start (re)implementing some basic movements
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/libide] libide: start (re)implementing some basic movements
- Date: Wed, 4 Mar 2015 07:55:12 +0000 (UTC)
commit e1d79a6acc595b88fd492e9f00ac803b24ac1e55
Author: Christian Hergert <christian hergert me>
Date: Tue Mar 3 23:54:26 2015 -0800
libide: start (re)implementing some basic movements
libide/ide-source-view-movements.c | 207 +++++++++++++++++++++++++++++++++++-
1 files changed, 206 insertions(+), 1 deletions(-)
---
diff --git a/libide/ide-source-view-movements.c b/libide/ide-source-view-movements.c
index fa6c5d3..c2b0e44 100644
--- a/libide/ide-source-view-movements.c
+++ b/libide/ide-source-view-movements.c
@@ -16,37 +16,242 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#define G_LOG_DOMAIN "ide-source-view"
+
+#include "ide-debug.h"
+#include "ide-enums.h"
#include "ide-source-view-movements.h"
+static void
+ide_source_view_movements_get_selection (IdeSourceView *self,
+ GtkTextIter *insert,
+ GtkTextIter *selection)
+{
+ GtkTextBuffer *buffer;
+ GtkTextMark *mark;
+
+ g_assert (IDE_IS_SOURCE_VIEW (self));
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self));
+
+ if (insert)
+ {
+ mark = gtk_text_buffer_get_insert (buffer);
+ gtk_text_buffer_get_iter_at_mark (buffer, insert, mark);
+ }
+
+ if (selection)
+ {
+ mark = gtk_text_buffer_get_selection_bound (buffer);
+ gtk_text_buffer_get_iter_at_mark (buffer, selection, mark);
+ }
+}
+
+static void
+ide_source_view_movements_select_range (IdeSourceView *self,
+ const GtkTextIter *insert,
+ const GtkTextIter *selection,
+ gboolean extend_selection)
+{
+ GtkTextBuffer *buffer;
+
+ g_assert (IDE_IS_SOURCE_VIEW (self));
+
+ buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (self));
+
+ if (extend_selection)
+ gtk_text_buffer_select_range (buffer, insert, selection);
+ else
+ gtk_text_buffer_select_range (buffer, insert, insert);
+}
+
+static void
+ide_source_view_movements_nth_char (IdeSourceView *self,
+ IdeSourceViewMovement movement,
+ gboolean extend_selection,
+ gint param)
+{
+ GtkTextIter insert;
+ GtkTextIter selection;
+
+ ide_source_view_movements_get_selection (self, &insert, &selection);
+
+ gtk_text_iter_set_line_offset (&insert, 0);
+
+ for (; param > 0; param--)
+ {
+ if (gtk_text_iter_ends_line (&insert))
+ break;
+ gtk_text_iter_forward_char (&insert);
+ }
+
+ ide_source_view_movements_select_range (self, &insert, &selection, extend_selection);
+}
+
+static void
+ide_source_view_movements_previous_char (IdeSourceView *self,
+ IdeSourceViewMovement movement,
+ gboolean extend_selection,
+ gint param)
+{
+ GtkTextIter insert;
+ GtkTextIter selection;
+
+ param = MAX (1, param);
+
+ ide_source_view_movements_get_selection (self, &insert, &selection);
+
+ for (; param; param--)
+ {
+ if (gtk_text_iter_starts_line (&insert))
+ break;
+ gtk_text_iter_backward_char (&insert);
+ }
+
+ ide_source_view_movements_select_range (self, &insert, &selection, extend_selection);
+}
+
+static void
+ide_source_view_movements_next_char (IdeSourceView *self,
+ IdeSourceViewMovement movement,
+ gboolean extend_selection,
+ gint param)
+{
+ GtkTextIter insert;
+ GtkTextIter selection;
+
+ param = MAX (1, param);
+
+ ide_source_view_movements_get_selection (self, &insert, &selection);
+
+ for (; param; param--)
+ {
+ if (gtk_text_iter_ends_line (&insert))
+ break;
+ gtk_text_iter_forward_char (&insert);
+ }
+
+ ide_source_view_movements_select_range (self, &insert, &selection, extend_selection);
+}
+
+static void
+ide_source_view_movements_first_char (IdeSourceView *self,
+ IdeSourceViewMovement movement,
+ gboolean extend_selection,
+ gint param)
+{
+ GtkTextIter insert;
+ GtkTextIter selection;
+
+ ide_source_view_movements_get_selection (self, &insert, &selection);
+
+ gtk_text_iter_set_line_offset (&insert, 0);
+
+ ide_source_view_movements_select_range (self, &insert, &selection, extend_selection);
+}
+
+static void
+ide_source_view_movements_first_nonspace_char (IdeSourceView *self,
+ IdeSourceViewMovement movement,
+ gboolean extend_selection,
+ gint param)
+{
+ GtkTextIter insert;
+ GtkTextIter selection;
+ gunichar ch;
+
+ ide_source_view_movements_get_selection (self, &insert, &selection);
+
+ gtk_text_iter_set_line_offset (&insert, 0);
+
+ while (!gtk_text_iter_ends_line (&insert) &&
+ (ch = gtk_text_iter_get_char (&insert)) &&
+ g_unichar_isspace (ch))
+ gtk_text_iter_forward_char (&insert);
+
+ ide_source_view_movements_select_range (self, &insert, &selection, extend_selection);
+}
+
+static void
+ide_source_view_movements_middle_char (IdeSourceView *self,
+ IdeSourceViewMovement movement,
+ gboolean extend_selection,
+ gint param)
+{
+ GtkTextIter insert;
+ GtkTextIter selection;
+ guint line_offset;
+
+ ide_source_view_movements_get_selection (self, &insert, &selection);
+
+ gtk_text_iter_forward_to_line_end (&insert);
+ line_offset = gtk_text_iter_get_line_offset (&insert);
+ gtk_text_iter_set_line_offset (&insert, line_offset >> 1);
+
+ ide_source_view_movements_select_range (self, &insert, &selection, extend_selection);
+}
+
+static void
+ide_source_view_movements_last_char (IdeSourceView *self,
+ IdeSourceViewMovement movement,
+ gboolean extend_selection,
+ gint param)
+{
+ GtkTextIter insert;
+ GtkTextIter selection;
+
+ ide_source_view_movements_get_selection (self, &insert, &selection);
+
+ gtk_text_iter_forward_to_line_end (&insert);
+
+ ide_source_view_movements_select_range (self, &insert, &selection, extend_selection);
+}
+
void
_ide_source_view_apply_movement (IdeSourceView *self,
IdeSourceViewMovement movement,
gboolean extend_selection,
gint param)
{
- g_assert (IDE_IS_SOURCE_VIEW (self));
+#ifndef IDE_DISABLE_TRACE
+ {
+ GEnumValue *enum_value;
+ GEnumClass *enum_class;
+
+ enum_class = g_type_class_peek (IDE_TYPE_SOURCE_VIEW_MOVEMENT);
+ enum_value = g_enum_get_value (enum_class, movement);
+ IDE_TRACE_MSG ("apply movement: %s", enum_value->value_nick);
+ }
+#endif
switch (movement)
{
case IDE_SOURCE_VIEW_MOVEMENT_NTH_CHAR:
+ ide_source_view_movements_nth_char (self, movement, extend_selection, param);
break;
case IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_CHAR:
+ ide_source_view_movements_previous_char (self, movement, extend_selection, param);
break;
case IDE_SOURCE_VIEW_MOVEMENT_NEXT_CHAR:
+ ide_source_view_movements_next_char (self, movement, extend_selection, param);
break;
case IDE_SOURCE_VIEW_MOVEMENT_FIRST_CHAR:
+ ide_source_view_movements_first_char (self, movement, extend_selection, param);
break;
case IDE_SOURCE_VIEW_MOVEMENT_FIRST_NONSPACE_CHAR:
+ ide_source_view_movements_first_nonspace_char (self, movement, extend_selection, param);
break;
case IDE_SOURCE_VIEW_MOVEMENT_MIDDLE_CHAR:
+ ide_source_view_movements_middle_char (self, movement, extend_selection, param);
break;
case IDE_SOURCE_VIEW_MOVEMENT_LAST_CHAR:
+ ide_source_view_movements_last_char (self, movement, extend_selection, param);
break;
case IDE_SOURCE_VIEW_MOVEMENT_PREVIOUS_WORD_START:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]