Applying a TextTag on newly-written Text



Hi Mailing List,

I have got a problem with Gtk::TextTag and applying them right after
text has been inserted: I handle the signal_insert event from the
TextBuffer and apply my tag (simplified) like that:

void Document::on_insert_after(const Gtk::TextBuffer::iterator& end,
                               const Glib::ustring& text,
                               int bytes)
{
	Gtk::TextBuffer::iterator pos = end;
	pos.backward_chars(text.length() );
        buffer->apply_tag_by_name("my-tag", pos, end);
}

This works quite fine, but the new tag (which should set the background
color of the text) is not drawn immediately on the TextView, but after
the view has been redrawn: For example by waiting until the cursor
blinks or by writing another character (the first character is tagged
then, the second not). However, calling queue_draw() after applying the
tag does not help.

I searched a bit in GtkSourceView's source code because their tags to
highlight source code show up immediately (even my tags do so if they
are in a line that was already highlighted by GtkSourceView!) but I
could not figure out how it works. They do something with an indle
handler, but applying the tags in an idle handler instead of the
signal_insert callback does not change anything :(

Another problem is that I do remove any tags in the region I want to add
the new one. This works fine, too, except if I paste text from a region
that has a tag set: In this case this tag seems not to be removed and
both tags (the old one got from the paste and the new one I apply when
text is inserted) are applied.

If this is the wrong mailing list for my problem and I should better use
one of GTK+'s, just tell me :)

Regards,
Armin



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