How to make cursor tooltip shown only when focused

Hi, I’m trying to make a custom cursor Tooltip by using the below example.
https://codemirror.net/examples/tooltip/

However, I’d like to not show the tooltip when editor is not focused.

Is there any way to achieve this?

I’ve read the documents to find some other status by using EditorState.
but not focused state.
(for ex, getting autocomplete completionStatus etc,)

Thank you

I’m sure this is not the answer,
but I found that when the editor is not focused,

transaction.selection is undefined
+
transaction.effects length is 0.

So I used
!tr.selection && tr.effects.length === 0
condition to check whether the editor is not focused.

Those have nothing at all to do with focus state, they just indicate transactions with no selection or effects.

Transactions act on the state level, and don’t know about the editor focus state, which is associated with a view. View updates can tell you whether the focus changed. Or, if you do need to integrate focus in your state, you can register a focus change effect and listen for transactions that include that.