I'm using Gtk.TextView
to display text, like this:
My goal is to programmatically move the cursor to the start of the next display line (not the start of a buffer line, but instead the first character in the next TextView
line).
It is using Gtk.WrapMode.WORD_CHAR
as a wrapping preference. Moving TextIter
objects works fine when accessed from the TextBuffer
:
/* This works as expected */
Gtk.TextIter start_iter;
buffer.get_start_iter (out start_iter);
Or when working directly with the TextIter
:
/* This also works as expected */
Gtk.TextIter iter;
...
iter.forward_line ();
But when I want to move the TextIter
using TextView
, e.g.:
Gtk.TextView text_view;
Gtk.TextIter iter;
...
text_view.forward_display_line (iter);
It doesn't move the iterator, despite forward_display_line
returning true
(signaling that the iterator has moved).
This is the code I'm using (inside of a class derived from TextView
):
Gtk.TextIter line_end;
/* Initializing TextIter, placing it at the start of the buffer. */
this.buffer.get_start_iter (out line_end);
print ("Offset before forwarding: %i\n", line_end.get_offset ()); //returns 0
this.forward_display_line (line_end);
print ("Offset after forwarding: %i\n", line_end.get_offset ()); // still returns 0
Why doesn't this code work? Are TextIter
s initialized by TextBuffer
not appropriate for TextView
methods?
As @José suggested, this is indeed a bug with Vala C bindings. The issue is posted here.
I will try to fix this bug, and will update this answer if I succeed in fixing it.