Gtk includes italic, bold, etc. in text form

[revised]

I am trying to use GTK3 TextView in C. I know how to apply tags like italics etc. to a text area.

But how do I "include" the style (italic, bold, etc.) when typing into the buffer? For example, let's say I am typing text and there are no styles set. Then I want to draw in italics. I want to apply an italic tag to the insertion point, after which everything I typed will be italicized.

I notice that when you position the cursor to the right of any existing styled text, the tags of the previous character are inherited, but only if the style is in effect before and after the insertion point. Interestingly, the trailing newline can be styled, so when the insertion point is at the end of the line and the last visible character has a style, then that style is inherited.

I've looked at some methods that use a keypress signal and then apply a text tag to the area of ​​the unlabeled character just printed, but this is slow and looks weird on screen - a regular char is displayed and then replaced with char tags.

I've also tried:

gtk_text_buffer_insert_markup(buf, &iter, "<i>", -1);

      

but gets a warning: Invalid markup string: ... Element 'markup' was closed, but the currently open element is 'i'

and does not affect the displayed text. The use <i></i>

gets no warning, but it also has no effect. I finally resorted to:

gtk_text_buffer_insert_markup(buf, &iter, "<i> </i>", -1); // 2 spaces gtk_text_iter_backward_char (&iter); gtk_text_buffer_place_cursor(buf, &iter);

which allows me to type italic between two new spaces - it's not that bad.

But pressing the "I" key to enter text in italics is a basic editing function that has been around for decades. It must be possible in GTK?

Any ideas?

thank

+3


source to share





All Articles