From 222bde7bee2da005ecf8f1d0d16a0eb223876c30 Mon Sep 17 00:00:00 2001 From: Milan Crha Date: Wed, 14 Feb 2024 11:04:55 +0100 Subject: [PATCH] I#2670 - Pasting into composer address box can lose spaces Closes https://gitlab.gnome.org/GNOME/evolution/-/issues/2670 --- src/e-util/e-name-selector-entry.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/e-util/e-name-selector-entry.c b/src/e-util/e-name-selector-entry.c index 338968cb90..ea6cb376c9 100644 --- a/src/e-util/e-name-selector-entry.c +++ b/src/e-util/e-name-selector-entry.c @@ -1442,8 +1442,9 @@ post_insert_update (ENameSelectorEntry *name_selector_entry, /* Returns the number of characters inserted */ static gint insert_unichar (ENameSelectorEntry *name_selector_entry, - gint *pos, - gunichar c) + gint *pos, + gunichar c, + gboolean *inout_is_first_char) { const gchar *text; gunichar str_context[4]; @@ -1457,7 +1458,7 @@ insert_unichar (ENameSelectorEntry *name_selector_entry, * - Before or after another space. * - At start of string. */ - if (c == ' ' && (str_context[1] == ' ' || str_context[1] == '\0' || str_context[2] == ' ')) + if (c == ' ' && *inout_is_first_char && str_context[0] && (str_context[1] == ' ' || str_context[1] == '\0' || str_context[2] == ' ')) return 0; /* Comma is not allowed: @@ -1508,11 +1509,15 @@ insert_unichar (ENameSelectorEntry *name_selector_entry, generate_attribute_list (name_selector_entry); } + *inout_is_first_char = TRUE; + return 2; } /* Generic case. Allowed spaces also end up here. */ + *inout_is_first_char = FALSE; + len = g_unichar_to_utf8 (c, buf); buf[len] = '\0'; @@ -1567,7 +1572,7 @@ user_insert_text (ENameSelectorEntry *name_selector_entry, * can be inserted, and insert a trailing space after comma. */ } else { const gchar *cp; - gboolean last_was_comma = FALSE; + gboolean last_was_comma = FALSE, is_first_char = TRUE; for (cp = new_text; *cp; cp = g_utf8_next_char (cp)) { gunichar uc = g_utf8_get_char (cp); @@ -1583,8 +1588,8 @@ user_insert_text (ENameSelectorEntry *name_selector_entry, last_was_comma = uc == ','; } - insert_unichar (name_selector_entry, position, uc); - chars_inserted++; + if (insert_unichar (name_selector_entry, position, uc, &is_first_char)) + chars_inserted++; } }