How do I find the active/focussed word in CM6?

Similar to how clicking on a line makes it activeLine, is there any way to find out where is the cursor on that active line and on which word/location?

Maybe EditorState.wordAt?

Yes right, but how do I get this position.

So my exact requirement is that when a user clicks on any word in the entire doc I want to enable and disable the buttons like Bold, Italic etc depending on the current word’s attributes. Perhaps a selection listener is a right phrase for it.

There’s no such thing as an active word in the editor’s state, so yes, I guess the selection is what you want to track here.

Is there some example I can take a look at to get this selection listener?

I think EditorView.updateListener is what you want. Call that with a function and add it to your list of extensions.

1 Like

Thanks, exactly what I need.