I'm using a CaretListener to listen to changs on the document. Each change comes in as a CaretEvent and, for the most part, everything is fine.
However, I have a problem with closing braces. For example, when I type
At the point when I type the opening brace (but haven't typed the closing), my caret (as per CaretEvent) is here:
But on the screen, the caret is already here:
As soon as I start typing, I get a caret event that moves it to the right place, but that event is too late. It only comes when I actually start typing, not before.
My question: how can I get the right caret position at a given point in time, taking into account smart brace closing? My code is as simple as
val position = caretEvent.caret?.offset ?: return