GNOME Bugzilla – Bug 304080
gtk_editable_select_region() gets undone in a "changed" callback function.
Last modified: 2014-03-27 10:08:34 UTC
Please describe the problem: If, in a callback function connected to the "changed", a user sets the "selected region" via gtk_editable_select_region(), the selection is lost if the trigger for the "change" had been a text insertion. On a deletion, however, the selection is not lost, but is correctly kept. Steps to reproduce: 1. attach the following function to the "changed" signal of a GTK_ENTRY void changed_text_handler(GtkEditable *editable, gpointer data) { gchar *text; text = gtk_editable_get_chars(editable, 0, -1); if (!strcmp(text, "ABC")) gtk_editable_select_region(editable, 1, 3); g_free(text); } 2. type "ABC" into the GTK_ENTRY (omit the ") 3. (nothing is selected...) 4. type "D" , then backspace (deleting the D) Actual results: after backspacing, the "BC" are selected. Expected results: the "BC" should have been selected immediately after typing the "C" Does this happen every time? yes Other information: i traced the bug to the gtk_entry_enter_text() function. Before the call to gtk_entry_set_position_internal(), we should check if selection bounds have been set. the following patch works FIX <> BUG 2753,2754c2753 < if (!gtk_editable_get_selection_bounds (editable, NULL, NULL)) /*ZS FIX */ < gtk_entry_set_position_internal (entry, tmp_pos, FALSE); --- > gtk_entry_set_position_internal (entry, tmp_pos, FALSE);
closing out old bugs