Closebrackets customization

Using CM6, I’d like to add a new char for closebrackets, but only when there’s a selection. I’ve been looking through the docs and code on closebrackets without any luck so far.

Here’s my use case: we have a syntax for highlighting markdown that’s done using == to enclose any text, for example regular ==highlighted== text. However, often times users want to type the = character like normal, without pairing it with a second one.

We’d like to configure closebrackets such that it does not automatically add a second closing = when typing normally, but only perform the auto closing when selecting the text and pressing =.

Here’s a short gif demonstrating the end result currently implemented in CM5.

Thank in advance for any tips!

That is indeed outside of what closebrackets supports, but it should be rather straightforward (using inputHandler similar to how closebrackets does it) to implement separately.

1 Like

Thank you! I have been successful in implementing a custom copy of the inputHandler based on the reference implementation from the closebrackets package.

How did you disable the original extension’s inputHandler?

My situation is that I want to disable closeBrackets during autocompletion, as I have a few snippets whose labels involve brackets. I’ve added this line to a custom copy of the input handler, and registered it as a plugin with high precedence, which works.

if (completionStatus(view.state) != null) return false;

But the problem is returning false just means that the old input handler from the closeBrackets() extension will handle it, and the bracket gets closed anyway, but returning true stops everything completely and the (opening) bracket won’t even be inserted.

EDIT: I misunderstood; I can remove closeBrackets and just register my new copy of the input handler. Sorry for reviving this topic; can’t believe I didn’t try that first!

EDIT: Although, now typing “through” a closed bracket doesn’t work because the state field is missing, which is not a public export, it seems. So my question still stands.

EDIT: I didn’t realize that closeBrackets() results in just a list of its two extensions, the input handler and state field; one can just take only the second element of this list and supply the custom input handler as a replacement for the first. This solved my issue completely!

Looks like you solved it, but I’ve ended up just adding the new handler for the specific things we needed to handle and let the original one take care of the ones it could.