[gnome-builder] editor: make trim trailing lines greedy for spaces.
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] editor: make trim trailing lines greedy for spaces.
- Date: Tue, 16 Sep 2014 07:15:13 +0000 (UTC)
commit 23ee08bd311db7208d3398844a8a59f57e0dea9d
Author: Christian Hergert <christian hergert me>
Date: Tue Sep 16 00:15:06 2014 -0700
editor: make trim trailing lines greedy for spaces.
src/editor/gb-editor-commands.c | 50 ++++++++++++++++++++++++++++++++++++--
1 files changed, 47 insertions(+), 3 deletions(-)
---
diff --git a/src/editor/gb-editor-commands.c b/src/editor/gb-editor-commands.c
index 7b55bf5..2bc1f4d 100644
--- a/src/editor/gb-editor-commands.c
+++ b/src/editor/gb-editor-commands.c
@@ -659,7 +659,47 @@ static gboolean
non_space_predicate (gunichar ch,
gpointer user_data)
{
- return !g_unichar_isspace (ch);
+ return g_unichar_isspace (ch);
+}
+
+static gboolean
+iter_backward_find_char_greedy (GtkTextIter *iter,
+ GtkTextCharPredicate predicate,
+ gpointer user_data,
+ const GtkTextIter *limit)
+{
+ gboolean found_char = FALSE;
+
+ g_return_val_if_fail (iter, FALSE);
+ g_return_val_if_fail (predicate, FALSE);
+ g_return_val_if_fail (limit, FALSE);
+
+ if (gtk_text_iter_compare (iter, limit) == 0)
+ return FALSE;
+
+ do {
+ gunichar ch;
+
+ if (!gtk_text_iter_backward_char (iter))
+ return found_char;
+
+ ch = gtk_text_iter_get_char (iter);
+
+ if (!predicate (ch, user_data))
+ {
+ if (found_char)
+ {
+ gtk_text_iter_forward_char (iter);
+ return TRUE;
+ }
+
+ return FALSE;
+ }
+
+ found_char = TRUE;
+ } while (gtk_text_iter_compare (iter, limit) >= 0);
+
+ return found_char;
}
static void
@@ -673,6 +713,8 @@ gb_editor_commands_trim_trailing_space (GbEditorWorkspace *workspace,
GtkTextIter begin;
GtkTextIter end;
+ ENTRY;
+
g_return_if_fail (GB_IS_EDITOR_WORKSPACE (workspace));
g_return_if_fail (GB_IS_EDITOR_TAB (tab));
@@ -692,8 +734,8 @@ gb_editor_commands_trim_trailing_space (GbEditorWorkspace *workspace,
gtk_text_iter_forward_to_line_end (&iter);
gtk_text_iter_assign (&line_end, &iter);
- if (gtk_text_iter_backward_find_char (&iter, non_space_predicate, NULL,
- &line_begin))
+ if (iter_backward_find_char_greedy (&iter, non_space_predicate, NULL,
+ &line_begin))
{
gtk_text_iter_forward_char (&iter);
gtk_text_buffer_delete (buffer, &iter, &line_end);
@@ -705,6 +747,8 @@ gb_editor_commands_trim_trailing_space (GbEditorWorkspace *workspace,
if (!gtk_text_iter_forward_char (&iter))
break;
}
+
+ EXIT;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]