我正在尝试使用Ace.js和Electron.js构建一个代码编辑器。到目前为止,我已经设置了这个编辑器,并且可以在其中编写代码。当我尝试将代码保存到文件中时,问题出现了。我的app.js文件中有以下代码:
editor.setTheme("ace/theme/monokai")
editor.session.setMode("ace/mode/arduino")
editor.setOptions({
fontFamily: "Fira Code",
fontSize: "10pt",
enableBasicAutocompletion: true,
enableSnippets: true,
showPrintMargin: false,
UseWrapMode: true,
UseSoftTabs: true,
})
beautify.beautify(editor.session)
code = editor.getValue()
save_file.addEventListener('click', () => {
window.eapi.saveFile('text.ino', code)
})
在我的index.js文件中,我有:
fs.writeFile(fname, code, (err) => {
if (err) {
console.log(err)
}
else {
console.log('Save succesful')
}
})
输出为
在编辑器中是这样的:
如有任何帮助,我们将不胜感激。
1条答案
按热度按时间nbysray51#
好了,我明白了。问题是
code
变量包含了编辑器中的代码,它是在按钮单击之前设置的。所以这是在HTML文件中设置的默认代码。这是我的一个愚蠢的错误。下面是编辑后的app.js文件