codemirror icon indicating copy to clipboard operation
codemirror copied to clipboard

Extending emmet to handle JS comment toggling

Open oskarkrawczyk opened this issue 9 years ago • 3 comments

Hey, this is Oskar from JSFiddle.

We have emmet enabled by default in JSFiddle, and always had the issue that a HTML comment is toggled within the JavaScript panel. Was looking into extending emmet to handle JS comments but can't figure out a good way to do so.

Any tips would be really appreciated.


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

oskarkrawczyk avatar Dec 05 '15 20:12 oskarkrawczyk

Hi,

currently, Emmet can (with some tweaking) comment with /* ... */, it doesn’t support single-line // ... commenting.

The best way to provide custom commenting logic is to override Emmet shortcut, check current syntax and, in case if it’s JS, use custom commenting logic, otherwise pass keyboard event further (to Emmet), e.g. return Codemirror.Pass object.

sergeche avatar Dec 07 '15 09:12 sergeche

Thanks @sergeche. The custom logic you mention, would the correct way be to built it on top of Emmet?If so can you point me to any resource that would help me understand how to add custom logic and trigger it using a shortcut?

oskarkrawczyk avatar Dec 07 '15 09:12 oskarkrawczyk

You need to simply register a key handler for Cmd-/ shortcut after initializing Emmet plugin (so it can take precedence): http://codemirror.net/doc/manual.html#keymaps

sergeche avatar Dec 07 '15 09:12 sergeche