Split leading digits from word during selection and word navigation

I’m working on a modified version of CoffeeScript using CodeMirror 6 in legacy mode.

How can I customize double-click selection behavior so that:

  • var222 is selected as a whole (default behavior),
  • but in the case of 222var, the leading digits (222) are selected separately from the word (var)?

I’m trying to treat leading numbers as a separate token during double-click selection / ctrl nav.

The library’s default behavior for double-click and by-group selection uses the character category system, which cannot express the kind of thing you’re looking for here. But you can of course provide your own cursor motion commands and mouse selection style to implement such a thing.

Thank you for the reply. Under cursor motion commands, do you mean re-binding arrow keys using keymap?

Yes. Only ctrl/cmd + horizontal arrows, in this case.

1 Like