[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
Re: GtkTextMark right gravity
- From: Darryl Ross <djr dazco com au>
- To: gtk-app-devel-list gnome org
- Subject: Re: GtkTextMark right gravity
- Date: Wed, 05 Feb 2003 17:37:58 +1100
Havoc Pennington wrote:
>On Wed, Feb 05, 2003 at 02:58:49PM +1100, Darryl Ross wrote:
>
>
>>I am trying to mark a section of text within a GtkTextBuffer and then
>>later retrieve the text along with any changes made within the section.
>>I have done the following:
>>
>> /* mark the section */
>> start_mark = gtk_text_buffer_create_mark(buffer, NULL, &iter, TRUE);
>> gtk_text_buffer_insert(buffer, &iter, "Hello, this is some text", -1);
>> end_mark = gtk_text_buffer_create_mark(buffer, NULL, &iter, FALSE);
>> /* here is some more text */
>> gtk_text_buffer_insert(buffer, &iter, "some more text", -1);
>>
>> /* retrieve the section */
>> gtk_text_buffer_get_iter_at_mark(buffer, &start, start_mark);
>> gtk_text_buffer_get_iter_at_mark(buffer, &end, end_mark);
>> text = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
>>
>>When I get the text the "some more text" text is included if end_mark
>>has left gravity set to false, but it is not included if end_mark has
>>left gravity set to true. I want end_mark to be right gravity as I want
>>insertions at the end of the section to remain within the marked section.
>>
>>
>>
>
>If end_mark has right gravity and you insert at end_mark, then the
>inserted text should be to the left of end_mark, thus inside your
>marked section.
>
>Is the problem just how to keep "some more text" from being inside the
>section? To do that you probably have to move the end_mark after
>inserting "some more text", or create end_mark after inserting it, or
>something.
>
Thanks for the help Havoc.
Ahh, now I get it. By putting a mark with right gravity at the end of my
text, the mark stays to the right of the next piece of text inserted by
my code. It's so obvious now :)
Here's my solution, just in case anyone wants to know:
/* mark the section */
start_mark = gtk_text_buffer_create_mark(buffer, NULL, &iter, TRUE);
gtk_text_buffer_insert(buffer, &iter, "Hello, this is some text", -1);
end_mark_left = gtk_text_buffer_create_mark(buffer, NULL, &iter, TRUE);
/* here is some more text */
gtk_text_buffer_insert(buffer, &iter, "some more text", -1);
/* now create a mark with right gravity at the end of the section
(marked by end_mark_left). */
gtk_text_buffer_get_iter_at_mark(buffer, &end_mark_iter, end_mark_left);
end_mark = gtk_text_buffer_create_mark(buffer, NULL, &end_mark_iter,
FALSE);
/* retrieve the section */
gtk_text_buffer_get_iter_at_mark(buffer, &start, start_mark);
gtk_text_buffer_get_iter_at_mark(buffer, &end, end_mark);
text = gtk_text_buffer_get_text(buffer, &start, &end, FALSE);
--
Darryl Ross
Principal Consultant, Dazco Technology ABN: 58 829 870 455
+61 3 9734 2466 http://www.dazco.com.au
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]