After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 304080 - gtk_editable_select_region() gets undone in a "changed" callback function.
gtk_editable_select_region() gets undone in a "changed" callback function.
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: Other
2.6.x
Other All
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2005-05-13 17:02 UTC by zvi sebrow
Modified: 2014-03-27 10:08 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description zvi sebrow 2005-05-13 17:02:06 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);
Comment 1 Matthias Clasen 2014-03-27 10:08:34 UTC
closing out old bugs