OscarGodson / EpicEditor

EpicEditor is an embeddable JavaScript Markdown editor with split fullscreen editing, live previewing, automatic draft saving, offline support, and more. For developers, it offers a robust API, can be easily themed, and allows you to swap out the bundled Markdown parser with anything you throw at it.
http://epiceditor.com
MIT License
4.25k stars 334 forks source link

How to clear the editor? [file methods should work when editor is not loaded] #152

Open bingomanatee opened 12 years ago

bingomanatee commented 12 years ago

I am having trouble clearing "History" from the epicEditor. Every time I return to the editor it has my old ocntent in it.

My code here:

   if (localStorage){
       localStorage.clear();
   }

    if (sessionStorage){
        sessionStorage.clear();
    }
    var editor = new EpicEditor({
        basePath:"/js/ne_blog/editor/epiceditor",
        theme:{
            base:"/themes/base/epiceditor.css",
            preview:"/themes/preview/github.css",
            editor:"/themes/editor/epic-light.css"
        }});
    editor.open('new');
    editor.importFile('new', ' foo bar ');
    editor.load();

doesn't do the trick - I'd expect to see "foo bar" but I see whatever I typed last visit.

How to ensure you are starting with a cherry entry field?

Thanks

Dave

OscarGodson commented 12 years ago

You shouldn't have to clear the localStorage and we don't use sessionStorage. importFile will just overwrite what you have. The problem is you're trying to open which puts content into the editor and the editor doesn't exist yet. You should actually see an error in your code above.

Try moving your load to above the open and importFile call like in my working example below: http://jsbin.com/owirij/edit

@johnmdonahue maybe we should handle all local file stuff better. Maybe we should guard against the editor not being loaded and doing all the localStorage stuff still. There's no reason you should have to have the editor loaded to importFile or open file actually. Thoughts?

I'm going to mark this as a "bug" since it does make sense that you should be able to setup all this stuff before loading the editor.

bingomanatee commented 12 years ago

I have put this code from your sample into my page

var editor = new EpicEditor({
    basePath:"https://raw.github.com/OscarGodson/EpicEditor/develop/epiceditor/",
    theme:{
        base:"/themes/base/epiceditor.css",
        preview:"/themes/preview/github.css",
        editor:"/themes/editor/epic-light.css"
    }});

editor.load();
editor.open('new');
editor.importFile('new', ' foo bar ');

but it only seems to work once; after that, the content continues to get sticky.

Is there any other bit of JS I can use to forcibly change the content, in the dom or the editor?

Dave

OscarGodson commented 12 years ago

Hmm, I can't repro here. The JSBin link also doesn't reproduce what you're saying for me. Does the JSBin link do it for you? For me each refresh it says "foo bar" no matter what I put in there before. importFile should overwrite what's ever there. Also, importFile automatically opens the file so you should be able to get rid of that open line.

This is where it sets the text: https://github.com/OscarGodson/EpicEditor/blob/68997cba2bbaaf4c8b4ac44bfe03966ecee33d97/src/editor.js#L1091

It doesn't have any real logic just puts whatever you give it in there. Odd.

What browser, browser version, and OS are you on? Also can you make a test case that does what you say in JSBin or can you provide a link?

bingomanatee commented 12 years ago

While not ideal, I found that lobotomizing all references to localStorage seems to obviate the problem.

I am working on my blog - it is all in local development but I should have it in a week or so at which point I'll push up a link.

Thanks for your help... Dave

bingomanatee commented 12 years ago

I have put in (verbatim) what I see in your code

var editor = new EpicEditor({
        basePath:"https://raw.github.com/OscarGodson/EpicEditor/develop/epiceditor/",
        theme:{
            base:"/themes/base/epiceditor.css",
            preview:"/themes/preview/github.css",
            editor:"/themes/editor/epic-light.css"
        }});

editor.load();
editor.open('new');
editor.importFile('new', ' foo bar ');
OscarGodson commented 12 years ago

So do you have the same issue at that JSBin link? If so what's your browser, version, and OS? I'm worried this is an actual bug of some kind. But yes, please send a link when you get a chance without your hacks that is a reproducible case

bingomanatee commented 12 years ago

I should be fairly close to being able to show you working / nonworking examples.

On Sun, Jul 15, 2012 at 10:26 AM, Oscar Godson reply@reply.github.com wrote:

So do you have the same issue at that JSBin link? If so what's your browser, version, and OS? I'm worried this is an actual bug of some kind. But yes, please send a link when you get a chance without your hacks that is a reproducible case


Reply to this email directly or view it on GitHub: https://github.com/OscarGodson/EpicEditor/issues/152#issuecomment-6993290

OscarGodson commented 12 years ago

Since it's been about 4 days I'm going to close this. If you can let me know if the JSBin link is a reproducible case or more info about the problem let me know and we can look into it more.

OscarGodson commented 12 years ago

Actually, I take that back, I've updated the title. This is still a stub to make it so you can do file manipulation without needing to load the actual editor.

bingomanatee commented 12 years ago

Lets see what happens when I take my project out of localhost.