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.