grapesjs icon indicating copy to clipboard operation
grapesjs copied to clipboard

BUG: editor.Panels.removeButton('options', 'preview') breaks View code

Open rudym87 opened this issue 6 years ago • 2 comments

Version: 0.16.18

Are you able to reproduce the bug from the demo? No

What is the expected behavior? I want to hide the default preview button while keeping the default "View code" button.

What is the current behavior? "View code" no longer works if the preview button is removed via

editor.Panels.removeButton('options', 'preview')

Are you able to attach screenshots, screencasts or a live demo?

Yes: JS Fiddle

rudym87 avatar Aug 13 '20 15:08 rudym87

Hi @rudym87 !

The problem seems to be caused by the deactivation of the button clicked to run the command (cf below), which causes the modal to instantly close.

https://github.com/artf/grapesjs/blob/a85126883fbeafe3a437b1421b952931a5aaafc0/src/commands/view/ExportTemplate.js#L5-L7

I have no idea why it only happens when the preview button has been removed, still it seems wierd to me to deactivate it while the code modal is still opened. I think it should rather be stored & disabled once the modal is closed (on stop), that way the button would stay active while the modal is open as shown in the following screenshot:

Screenshot 2020-08-27 at 3 16 24 PM

This fixes the aforementioned problem, & is also visually more coherent in my opinion. @artf what do you think ? As always, I'd be happy to open a PR for this :) !

Cheers !

mcottret avatar Aug 27 '20 14:08 mcottret

correct @mcottret, honestly, I don't even see the reason anymore to keep this command stateful. So, I'd remove that useless sender.set('active', 0) and the stop function from it. Let me know if you have a better idea

artf avatar Aug 28 '20 16:08 artf