[gtksourceview] SpaceDrawer: take into account implicit trailing newline
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] SpaceDrawer: take into account implicit trailing newline
- Date: Sat, 23 Jul 2016 08:27:19 +0000 (UTC)
commit 49cc347f824cb100994885efeeb03a89f92c3857
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sat Jul 23 09:10:19 2016 +0200
SpaceDrawer: take into account implicit trailing newline
This starts to become interesting.
gtksourceview/gtksourcespacedrawer.c | 26 ++++++++++++++++++--------
tests/test-space-drawing.c | 8 ++++++++
2 files changed, 26 insertions(+), 8 deletions(-)
---
diff --git a/gtksourceview/gtksourcespacedrawer.c b/gtksourceview/gtksourcespacedrawer.c
index fc0edbc..af3a508 100644
--- a/gtksourceview/gtksourcespacedrawer.c
+++ b/gtksourceview/gtksourcespacedrawer.c
@@ -194,11 +194,19 @@ is_space (gunichar ch)
return g_unichar_type (ch) == G_UNICODE_SPACE_SEPARATOR;
}
-static inline gboolean
+static gboolean
is_newline (const GtkTextIter *iter)
{
- /* TODO take into account implicit trailing newline. */
- return gtk_text_iter_ends_line (iter) && !gtk_text_iter_is_end (iter);
+ if (gtk_text_iter_is_end (iter))
+ {
+ GtkSourceBuffer *buffer;
+
+ buffer = GTK_SOURCE_BUFFER (gtk_text_iter_get_buffer (iter));
+
+ return gtk_source_buffer_get_implicit_trailing_newline (buffer);
+ }
+
+ return gtk_text_iter_ends_line (iter);
}
static inline gboolean
@@ -649,17 +657,20 @@ _gtk_source_space_drawer_draw (GtkSourceSpaceDrawer *drawer,
gunichar ch = gtk_text_iter_get_char (&iter);
gint ly;
- if (is_whitespace (ch) &&
+ /* Allow end iter, to draw implicit trailing newline. */
+ if ((is_whitespace (ch) || gtk_text_iter_is_end (&iter)) &&
space_needs_drawing (drawer, &iter, &leading_end, &trailing_start))
{
draw_whitespace_at_iter (text_view, &iter, cr);
}
- if (!gtk_text_iter_forward_char (&iter))
+ if (gtk_text_iter_is_end (&iter))
{
break;
}
+ gtk_text_iter_forward_char (&iter);
+
if (gtk_text_iter_compare (&iter, &line_end) > 0)
{
if (gtk_text_iter_compare (&iter, &end) > 0)
@@ -670,10 +681,9 @@ _gtk_source_space_drawer_draw (GtkSourceSpaceDrawer *drawer,
/* Move to the first iter in the exposed area of the
* next line.
*/
- if (!gtk_text_iter_starts_line (&iter) &&
- !gtk_text_iter_forward_line (&iter))
+ if (!gtk_text_iter_starts_line (&iter))
{
- break;
+ gtk_text_iter_forward_line (&iter);
}
gtk_text_view_get_line_yrange (text_view, &iter, &ly, NULL);
diff --git a/tests/test-space-drawing.c b/tests/test-space-drawing.c
index 747fbab..5f010aa 100644
--- a/tests/test-space-drawing.c
+++ b/tests/test-space-drawing.c
@@ -75,6 +75,7 @@ create_window (void)
GtkWidget *gsv_checkbutton;
GtkWidget *tag_set_checkbutton;
GtkWidget *tag_checkbutton;
+ GtkWidget *implicit_trailing_newline_checkbutton;
GtkSourceView *view;
GtkSourceBuffer *buffer;
GtkTextTag *tag;
@@ -136,6 +137,13 @@ create_window (void)
tag, "draw-spaces",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+ implicit_trailing_newline_checkbutton = gtk_check_button_new_with_label ("Implicit trailing newline");
+ gtk_widget_set_margin_top (implicit_trailing_newline_checkbutton, 12);
+ gtk_container_add (GTK_CONTAINER (panel_grid), implicit_trailing_newline_checkbutton);
+ g_object_bind_property (buffer, "implicit-trailing-newline",
+ implicit_trailing_newline_checkbutton, "active",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (view));
gtk_container_add (GTK_CONTAINER (hgrid), scrolled_window);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]