Re: Text widget delete bug example




Tony Gale <gale@daedalus.dra.hmg.gb> writes:

> As requested by Owen :-) here is a piece of example code that
> illustrates the Text Widget delete bug.
> 
> Just keep hitting the 'add line' button, and when it reaches more
> than 10 lines, which is when it starts deleting text, the bug will
> become clear - the number should continue to increase.

Thanks for the example. It should be useful. Actually, looking
at Josh Macdonald's docs for the Text widget (see
docs/text_widget.txt), this was something that was never implemented
fully - gtk_text_delete_[forward/backward] don't reexpose the
buffer.

>  if (numlines > 10) {
>     gtk_text_freeze(GTK_TEXT(text));
>     while( GTK_TEXT(text)->text[numchars] && 
>            (GTK_TEXT(text)->text[numchars] != '\n') ) {
>       numchars++;

This will get you into trouble. (Though it isn't the problem
here) The text widget uses a gapped buffer, so just getting
a character like that is wrong.

The macro TEXT_INDEX() in gtktext.c should possibly be moved
into gtktext.h and renamed.

#define TEXT_INDEX(t, index)        ((index) < (t)->gap_position ? (t)->text[index] : \
				     (t)->text[(index) + (t)->gap_size])

On the other hand, maybe it should be a function - with debugging
turned on:

  TEXT_INDEX(GTK_TEXT(text), index)

is going to check the cast 4 times and be incredibly slow... (so
do do that!) There also should be some functions for getting
chunks of text out of the buffer.

See the above mentioned text_widget.txt for an explaination of
what is meant by a gapped buffer.

Regards,
                                        Owen



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