How to save or edit javascript files in ace editor

后端 未结 2 1223
生来不讨喜
生来不讨喜 2021-01-29 07:59

I want to use the Ace editor to save and edit javascript files it\'s not clear in the documentation how to do that.

相关标签:
2条回答
  • 2021-01-29 08:29

    Lets say you have a button called download, this is how you would do it

    I am using the filesaver.js library that you can find HERE

    document.getElementById("download").addEventListener("click", ()=>{
          var file = new File([editor.getValue()], "zup.js", {type: "text/plain;charset=utf-8"});
          saveAs(file);
    })
    
    0 讨论(0)
  • 2021-01-29 08:31

    Ace editor is only the UI part of the editor. Think of it as: like a textarea but cool!.
    To deal with files you need some kind of server that will read and save the files and will send the text to the webpage where Ace lives. (You can also use html5 filesystem api, but that only works on chrome).
    You can find many interesting implementations of this in Zed source code at https://github.com/zedapp/zed/tree/master/app/js/fs, which is a code editor based on Ace.

    0 讨论(0)
提交回复
热议问题