[gtksourceview/wip/search-word-boundaries: 1/2] iter: add visible option to starts/ends_extra_natural_word()
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/search-word-boundaries: 1/2] iter: add visible option to starts/ends_extra_natural_word()
- Date: Sat, 11 Jun 2016 16:51:57 +0000 (UTC)
commit 958eadb4d69ddea793fffe71050453eba024caee
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sat Jun 11 18:40:48 2016 +0200
iter: add visible option to starts/ends_extra_natural_word()
And make those functions semi-public.
They will be useful in GtkSourceSearchContext.
gtksourceview/gtksourceiter.c | 32 +++++++++++++++++++++++---------
gtksourceview/gtksourceiter.h | 16 +++++++++-------
testsuite/test-iter.c | 4 ++--
3 files changed, 34 insertions(+), 18 deletions(-)
---
diff --git a/gtksourceview/gtksourceiter.c b/gtksourceview/gtksourceiter.c
index 20c5242..b38db4d 100644
--- a/gtksourceview/gtksourceiter.c
+++ b/gtksourceview/gtksourceiter.c
@@ -2,7 +2,7 @@
/* gtksourceiter.c
* This file is part of GtkSourceView
*
- * Copyright (C) 2014 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2014, 2016 - Sébastien Wilmet <swilmet gnome org>
*
* GtkSourceView is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -251,8 +251,21 @@ _gtk_source_iter_backward_extra_natural_word_start (GtkTextIter *iter)
}
}
+static gboolean
+backward_cursor_position (GtkTextIter *iter,
+ gboolean visible)
+{
+ if (visible)
+ {
+ return gtk_text_iter_backward_visible_cursor_position (iter);
+ }
+
+ return gtk_text_iter_backward_cursor_position (iter);
+}
+
gboolean
-_gtk_source_iter_starts_extra_natural_word (const GtkTextIter *iter)
+_gtk_source_iter_starts_extra_natural_word (const GtkTextIter *iter,
+ gboolean visible)
{
gboolean starts_word;
GtkTextIter prev;
@@ -260,7 +273,7 @@ _gtk_source_iter_starts_extra_natural_word (const GtkTextIter *iter)
starts_word = gtk_text_iter_starts_word (iter);
prev = *iter;
- if (!gtk_text_iter_backward_visible_cursor_position (&prev))
+ if (!backward_cursor_position (&prev, visible))
{
return starts_word || gtk_text_iter_get_char (iter) == '_';
}
@@ -276,13 +289,14 @@ _gtk_source_iter_starts_extra_natural_word (const GtkTextIter *iter)
}
gboolean
-_gtk_source_iter_ends_extra_natural_word (const GtkTextIter *iter)
+_gtk_source_iter_ends_extra_natural_word (const GtkTextIter *iter,
+ gboolean visible)
{
GtkTextIter prev;
gboolean ends_word;
prev = *iter;
- if (!gtk_text_iter_backward_visible_cursor_position (&prev))
+ if (!backward_cursor_position (&prev, visible))
{
return FALSE;
}
@@ -510,28 +524,28 @@ gboolean
_gtk_source_iter_starts_word (const GtkTextIter *iter)
{
if (_gtk_source_iter_starts_full_word (iter) ||
- _gtk_source_iter_starts_extra_natural_word (iter))
+ _gtk_source_iter_starts_extra_natural_word (iter, TRUE))
{
return TRUE;
}
/* Example: "abcd|()", at the start of the word "()". */
return (!_gtk_source_iter_ends_full_word (iter) &&
- _gtk_source_iter_ends_extra_natural_word (iter));
+ _gtk_source_iter_ends_extra_natural_word (iter, TRUE));
}
gboolean
_gtk_source_iter_ends_word (const GtkTextIter *iter)
{
if (_gtk_source_iter_ends_full_word (iter) ||
- _gtk_source_iter_ends_extra_natural_word (iter))
+ _gtk_source_iter_ends_extra_natural_word (iter, TRUE))
{
return TRUE;
}
/* Example: "abcd()|efgh", at the end of the word "()". */
return (!_gtk_source_iter_starts_full_word (iter) &&
- _gtk_source_iter_starts_extra_natural_word (iter));
+ _gtk_source_iter_starts_extra_natural_word (iter, TRUE));
}
gboolean
diff --git a/gtksourceview/gtksourceiter.h b/gtksourceview/gtksourceiter.h
index f7e0825..fe824f7 100644
--- a/gtksourceview/gtksourceiter.h
+++ b/gtksourceview/gtksourceiter.h
@@ -2,7 +2,7 @@
/* gtksourceiter.h
* This file is part of GtkSourceView
*
- * Copyright (C) 2014 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright (C) 2014, 2016 - Sébastien Wilmet <swilmet gnome org>
*
* GtkSourceView is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -48,6 +48,14 @@ void _gtk_source_iter_extend_selection_word (const GtkTextIter
*location,
GtkTextIter *start,
GtkTextIter *end);
+GTK_SOURCE_INTERNAL
+gboolean _gtk_source_iter_starts_extra_natural_word (const GtkTextIter *iter,
+ gboolean visible);
+
+GTK_SOURCE_INTERNAL
+gboolean _gtk_source_iter_ends_extra_natural_word (const GtkTextIter *iter,
+ gboolean visible);
+
/* Internal functions, in the header for unit tests. */
GTK_SOURCE_INTERNAL
@@ -69,12 +77,6 @@ GTK_SOURCE_INTERNAL
void _gtk_source_iter_backward_extra_natural_word_start (GtkTextIter *iter);
GTK_SOURCE_INTERNAL
-gboolean _gtk_source_iter_starts_extra_natural_word (const GtkTextIter *iter);
-
-GTK_SOURCE_INTERNAL
-gboolean _gtk_source_iter_ends_extra_natural_word (const GtkTextIter *iter);
-
-GTK_SOURCE_INTERNAL
gboolean _gtk_source_iter_starts_word (const GtkTextIter *iter);
GTK_SOURCE_INTERNAL
diff --git a/testsuite/test-iter.c b/testsuite/test-iter.c
index cbbdd0b..55b0ed8 100644
--- a/testsuite/test-iter.c
+++ b/testsuite/test-iter.c
@@ -217,7 +217,7 @@ check_starts_extra_natural_word (const gchar *buffer_text,
gtk_text_buffer_set_text (buffer, buffer_text, -1);
gtk_text_buffer_get_iter_at_offset (buffer, &iter, offset);
- g_assert_cmpint (starts, ==, _gtk_source_iter_starts_extra_natural_word (&iter));
+ g_assert_cmpint (starts, ==, _gtk_source_iter_starts_extra_natural_word (&iter, TRUE));
g_object_unref (buffer);
}
@@ -250,7 +250,7 @@ check_ends_extra_natural_word (const gchar *buffer_text,
gtk_text_buffer_set_text (buffer, buffer_text, -1);
gtk_text_buffer_get_iter_at_offset (buffer, &iter, offset);
- g_assert_cmpint (ends, ==, _gtk_source_iter_ends_extra_natural_word (&iter));
+ g_assert_cmpint (ends, ==, _gtk_source_iter_ends_extra_natural_word (&iter, TRUE));
g_object_unref (buffer);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]