Problem selecting a region in a GtkTextBuffer



I am having problems with code that should select a region in a GTK+
text buffer but does not appear to work.  I am using GTK+ 2.0.6 on
a RedHat 8.0 system.

Here is the function, where 'start' and 'end' are character
offsets (not byte offsets) into the text buffer.  I call
gtk_widget_grab_focus() to be sure to see any results.

void select_text_region(GtkWidget *text_view, gint start, gint end)
{
    GtkTextBuffer *buf;
    GtkTextIter start_it, end_it;
    GtkTextMark *mark;

    gtk_widget_grab_focus(text_view);
    buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text_view));
    gtk_text_buffer_get_iter_at_offset(buf, &start_it, start);
    gtk_text_buffer_place_cursor(buf, &start_it);
    gtk_text_buffer_get_iter_at_offset(buf, &end_it, end);
    mark = gtk_text_buffer_get_selection_bound(buf);
    gtk_text_buffer_move_mark(buf, mark, &end_it);
}

In the case I'm trying to debug, 'start' is 15 and 'end' is 16,
and the text buffer contains 500 characters.  The vertical line
representing the cursor ends up at position 15.  The character
at position 15 should however be highlighted but is not.

Does this code overlook something?  Thanks.

-- 
Pierre Sarrazin <sarrazip at sympatico dot ca>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]