TextEditor API -- programmatic cursor movement?

I’m starting to use the text_editor widget on mainline. I know it’s brand new. After bit of searching and tinkering, I suspect the API is missing something (unless I didn’t see it).

My use case is to move the cursor to a specific location under program control. I’m using the TextEditor widget to let users enter programs. When they make an error, I want to move the cursor to the offending line, ideally also selecting the text range).

It seems currently one can only query the cursor or find the text of the line starting at a given line number from text_editor::Content.

I tried the following as a workaround, but it seems not to have any effect (i.e. Action::Scroll is inert, it seems – even using only Action::Scroll by itself does nothing):

self.text_content.perform(text_editor::Action::Move(text_editor::Motion::DocumentStart)); // works
self.text_content.perform(text_editor::Action::Scroll{ lines: the_error_line });  // no apparent effect

Is there some better way to do this that I might have missed?

1 Like