diff options
| author | Matthew Barnes <mbarnes@redhat.com> | 2010-07-13 17:26:17 -0400 |
|---|---|---|
| committer | Matthew Barnes <mbarnes@redhat.com> | 2010-07-13 17:33:28 -0400 |
| commit | 210654aeb561de6cba2e7f2508f97fee8fbb293f (patch) | |
| tree | 3e3166955ef220ddf2171dc9ba85d24d10dfe31a | |
| parent | 135f4f5be01d367f97f73341611137025cb8001c (diff) | |
| download | evolution-data-server-210654aeb561de6cba2e7f2508f97fee8fbb293f.tar.gz | |
Bug 608299 - Cut/copy error when selection has trailing comma
When cutting or copying a selection that includes a trailing comma, the
subsequent address was also getting copied to the clipboard. The fix is
to ignore trailing whitespace and commas when scanning the selection for
email addresses.
| -rw-r--r-- | libedataserverui/e-name-selector-entry.c | 45 |
1 files changed, 30 insertions, 15 deletions
diff --git a/libedataserverui/e-name-selector-entry.c b/libedataserverui/e-name-selector-entry.c index 093d52d00..59ace1295 100644 --- a/libedataserverui/e-name-selector-entry.c +++ b/libedataserverui/e-name-selector-entry.c @@ -2611,30 +2611,43 @@ populate_popup (ENameSelectorEntry *name_selector_entry, GtkMenu *menu) } static void -copy_or_cut_clipboard (ENameSelectorEntry *name_selector_entry, gboolean is_cut) +copy_or_cut_clipboard (ENameSelectorEntry *name_selector_entry, + gboolean is_cut) { - gint i, start = 0, end = 0; - const gchar *text; + GtkClipboard *clipboard; + GtkEditable *editable; + const gchar *text, *cp; GHashTable *hash; GHashTableIter iter; gpointer key, value; GString *addresses; + gint ii, start, end; + gunichar uc; - text = gtk_entry_get_text (GTK_ENTRY (name_selector_entry)); - - if (!gtk_editable_get_selection_bounds (GTK_EDITABLE (name_selector_entry), &start, &end)) { - start = gtk_editable_get_position (GTK_EDITABLE (name_selector_entry)); - end = start; - } + editable = GTK_EDITABLE (name_selector_entry); + text = gtk_entry_get_text (GTK_ENTRY (editable)); - /* do nothing when there is nothing selected */ - if (start == end) + if (!gtk_editable_get_selection_bounds (editable, &start, &end)) return; + g_return_if_fail (end > start); + hash = g_hash_table_new (g_direct_hash, g_direct_equal); - for (i = start; i <= end; i++) { - gint index = get_index_at_position (text, i); + ii = end; + cp = g_utf8_offset_to_pointer (text, end); + uc = g_utf8_get_char (cp); + + /* Exclude trailing whitespace and commas. */ + while (ii >= start && (uc == ',' || g_unichar_isspace (uc))) { + cp = g_utf8_prev_char (cp); + uc = g_utf8_get_char (cp); + ii--; + } + + /* Determine the index of each remaining character. */ + while (ii >= start) { + gint index = get_index_at_position (text, ii--); g_hash_table_insert (hash, GINT_TO_POINTER (index), NULL); } @@ -2676,11 +2689,13 @@ copy_or_cut_clipboard (ENameSelectorEntry *name_selector_entry, gboolean is_cut) } if (is_cut) - gtk_editable_delete_text (GTK_EDITABLE (name_selector_entry), start, end); + gtk_editable_delete_text (editable, start, end); g_hash_table_unref (hash); - gtk_clipboard_set_text (gtk_widget_get_clipboard (GTK_WIDGET (name_selector_entry), GDK_SELECTION_CLIPBOARD), addresses->str, -1); + clipboard = gtk_widget_get_clipboard ( + GTK_WIDGET (name_selector_entry), GDK_SELECTION_CLIPBOARD); + gtk_clipboard_set_text (clipboard, addresses->str, -1); g_string_free (addresses, TRUE); } |
