2021-10-19 09:28:38 +00:00
|
|
|
{{define "components/editor"}}
|
2021-10-20 15:58:14 +00:00
|
|
|
{{template "components/toolbar" .}}
|
|
|
|
|
2021-10-21 08:04:57 +00:00
|
|
|
<!-- <container class="container is-max-desktop"> -->
|
2021-10-20 15:58:14 +00:00
|
|
|
<div id="editor">{{.File.Content}}</div>
|
2021-10-21 08:04:57 +00:00
|
|
|
<!-- </container> -->
|
2021-10-20 15:58:14 +00:00
|
|
|
<script>
|
|
|
|
function setEditor(){
|
|
|
|
var beautify = ace.require("ace/ext/beautify");
|
|
|
|
window.beautify = beautify
|
|
|
|
var editor = ace.edit("editor");
|
|
|
|
window.editor = editor
|
|
|
|
editor.setTheme("ace/theme/monokai");
|
|
|
|
editor.session.setMode("ace/mode/{{.Editor.Lang}}");
|
|
|
|
editor.session.setUseWrapMode(false);
|
|
|
|
editor.session.setNewLineMode('{{.Editor.Platform}}')
|
|
|
|
editor.setReadOnly({{.File.RO}});
|
2021-10-23 04:56:24 +00:00
|
|
|
|
|
|
|
editor.session.on('change', function(delta) {
|
|
|
|
// delta.start, delta.end, delta.lines, delta.action
|
|
|
|
window.ContentChanged = true
|
|
|
|
});
|
|
|
|
|
|
|
|
editor.commands.addCommand({
|
|
|
|
name: 'SaveContent',
|
|
|
|
bindKey: {win: 'Ctrl-S', mac: 'Command-S'},
|
|
|
|
exec: function(editor) {
|
|
|
|
//...
|
|
|
|
FileSave()
|
|
|
|
},
|
|
|
|
readOnly: false // false if this command should not apply in readOnly mode
|
|
|
|
});
|
2021-10-24 06:32:55 +00:00
|
|
|
editor.commands.addCommand({
|
|
|
|
name: 'Reload',
|
|
|
|
bindKey: {win: 'F5', mac: 'Command-R'},
|
|
|
|
exec: function(editor) {
|
|
|
|
if (window.ContentChanged)
|
|
|
|
if(confirm("You have unsaved changes, are you sure to reload?"))
|
|
|
|
window.location.reload()
|
|
|
|
},
|
|
|
|
readOnly: false
|
|
|
|
});
|
|
|
|
editor.commands.addCommand({
|
|
|
|
name: 'SaveAndApply',
|
|
|
|
bindKey: {win: 'Ctrl-E', mac: 'Command-E'},
|
|
|
|
exec: function(editor) {
|
|
|
|
if ('{{.File.Name}}'=='{{.AppName}}') toolSave()
|
|
|
|
else toolApply()
|
|
|
|
},
|
|
|
|
readOnly: true
|
|
|
|
});
|
2021-10-20 15:58:14 +00:00
|
|
|
}
|
|
|
|
</script>
|
2021-10-19 09:28:38 +00:00
|
|
|
{{end}}
|