easy-markdown-editor icon indicating copy to clipboard operation
easy-markdown-editor copied to clipboard

Method `isPreviewActive()` is not working properly

Open johnny243 opened this issue 4 years ago • 0 comments

Describe the bug The isPreviewActive() method is returning false, whether the preview mode is active or not.

Steps to reproduce the behavior:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Example / Preview</title>
    <link rel="stylesheet" href="../dist/easymde.min.css">
    <script src="../dist/easymde.min.js"></script>
</head>

<body>
    <textarea></textarea>
    <script>
        const easyMDE = new EasyMDE({
            toolbar: [
                {
                    className: 'fa fa-eye',
                    default: true,
                    name: 'preview',
                    noDisable: true,
                    title: 'Toggle Preview',
                    action: handleTogglePreview
                },
                '|',
                'heading', 'bold', 'italic', 'strikethrough',
                '|', 'quote', 'code',
                '|', 'unordered-list', 'ordered-list',
                '|', 'clean-block',
                '|', 'link', 'image',
                '|', 'table'
            ],
        });

        function handleTogglePreview() {
            easyMDE.togglePreview();

            // easyMDE.isPreviewActive() is always false.
            if (easyMDE.isPreviewActive()) {
                console.log('Preview is active.');
            } else {
                console.log('Preview is NOT active.');
            }
        }
    </script>
</body>

</html>
  1. Copy the code above into an HTML file (update paths to easymde.min.js and easymde.min.css accordingly)
  2. Open the HTML file in a browser
  3. Click the Toggle preview button
  4. easyMDE.isPreviewActive() returns false
  5. Click the Toggle preview button
  6. easyMDE.isPreviewActive() returns false again

Expected behavior easyMDE.isPreviewActive() should return true when preview mode is active. Else, false.

Version information

  • OS: Ubuntu 20.04.1 LTS
  • Browser: 89.0.4389.114
  • EasyMDE version: 2.15.0 (latest)

Additional context

  • https://github.com/Ionaru/easy-markdown-editor/blob/dbab7e95e7777d353b1600729709f01b876565f9/src/js/easymde.js#L2859
  • easyNDE.isSideBySideActive() has the same issue.

johnny243 avatar May 13 '21 19:05 johnny243