Textualize/textual

Make `cursor_location` a reactive attribute

Closed this issue · 4 comments

I'm using a TextArea to create a fairly specific 'editor' Widget, and would like to constantly report to the user what the location of their cursor is (i.e., offset from the start of the line), like many editors do in the their footer.

Rather than polling the current value of cursor_location, it would be nice if this is a reactive attribute that I can watch for.

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

You might instead watch the TextArea.selection which is a reactive attribute, or handle the SelectionChanged messages.

@property
def cursor_location(self) -> Location:
"""The current location of the cursor in the document.
This is a utility for accessing the `end` of `TextArea.selection`.
"""
return self.selection.end

Excellent! That solved my issue perfectly.

Don't forget to star the repository!

Follow @textualizeio for Textual updates.