PrismJS / live

Prism Live: Lightweight, extensible editable code editors. A work in progress, try it out at your own risk (and report bugs!) :)
https://live.prismjs.com
MIT License
105 stars 27 forks source link

Disable automatic bracket/quote closing #7

Open Zei33 opened 3 years ago

Zei33 commented 3 years ago

Love the extension, it works so well. How can I disable the automatic bracket/quote closing functionality?

When I type (or ", I'd rather it didn't add ) or " after.

Can't seem to find where that code is.

Thanks for all your efforts.

LeaVerou commented 3 years ago

In all languages or a specific one?

AgentEnder commented 3 years ago

Lea, what do you think about this approach for allowing the behavior to be toggled off? https://github.com/AgentEnder/live/tree/feat/allow-disabling-of-pairs

Zei33 commented 3 years ago

@LeaVerou In my case I just need to disable it completely on a specific textarea. I'm adding prism \

\ blocks inside the textarea and as I type the code, it's matching the pairs which is functionality I'd like to avoid as a personal choice.
@AgentEnder ah I see where the code is now. I didn't know the term used was "pairs". I can edit the code in my project manually now.
Still, I think it would be useful to add the functionality to toggle it to the main release.

Thanks for the help!

AgentEnder commented 3 years ago

@LeaVerou if you don't think the data-plMatchPairs attribute is appropriate, this could also be a flag set on the global Prism.Live config option. Something such as Prism.Live.matchPairs = true by default, and then a user could override it by setting the variable to false in a script file.

If its ok with you, I'll open a PR with my current impl. and we can continue the discussion on it. https://github.com/prismjs/live/compare/master...agentender:feat/allow-disabling-of-pairs

LeaVerou commented 3 years ago

Would running this work for you or are you looking for an HTML-based way?

Prism.Live.pairs = {};
Zei33 commented 3 years ago

@LeaVerou I think that should work. I can't speak for others but I'm only using one textarea so it's fine in my case.

LeaVerou commented 3 years ago

Oh I see, @AgentEnder wants to disable on a specific textarea. That won't work then, it needs to be an attribute.

The currently proposed design violates several HTML design principles, but the general idea is sound.

I'd suggest a data-pl-pairs attribute, that takes a comma separated list of pairs (e.g. data-pairs="( ), [ ]"). An empty value or the keyword"none"` would mean no pairs.

AgentEnder commented 3 years ago

Gotcha @LeaVerou . I'll update the branch and open a PR

AgentEnder commented 3 years ago

@LeaVerou any updates on this one?

LeaVerou commented 3 years ago

I wonder if the reason you are asking to disable it is because it doesn't work so well in some cases. If so, perhaps we should focus on fixing it for those cases? Just a thought.

AgentEnder commented 3 years ago

Honestly, at this point I've not used prism in about a year, let alone prism live. Nothing against the either library as I love them both, I've just not had a recent need. Unfortunately, this means I don't really remember the pain point I had encountered.

I don't care to close out that PR, if others are not running into similar pain points.

Zei33 commented 3 years ago

The reason I was hoping for the feature was because I was writing a blog about programming so the automatic closing was just inconvenient. I still think it would be a good option to have, and I'll certainly be using the library again in the future. Currently I'm not using it either so I have no immediate need for the change.

bricebou commented 2 years ago

Hi,

Any update on this issue and the proposed PR ? I've included PrismLive inside a plugin for SPIP CMS and had to modify the script to add the ability to configure which pairs to be enabled. It would be great if we can simply pass options to the PrismLive instance.

Thanks !

LeaVerou commented 2 years ago

I'd love to merge a PR on this, and to work with someone to implement this functionality with a good API. I don't have time to implement it myself currently. The linked PR is closed, but I just commented if the OP wants to pick this back up.