change to basic <textarea> version

This commit is contained in:
foamyguy 2022-07-25 19:15:43 -05:00
parent 541e448100
commit a33985a73f
2 changed files with 6 additions and 75 deletions

View File

@ -14,26 +14,12 @@
font-size: 0.7em;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"
integrity="sha512-c3Nl8+7g4LMSTdrm621y7kf9v3SDPnhxLNhcjFJbKECVnmZHTdo+IRO05sNLTH/D3vA6u1X32ehoLC7WFVdheg=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.6.0/ace.min.js"
integrity="sha512-Ky7AOm/5oRYp5QzV9diL95tE/OKjzfAkugQ+llHy1scOlzIyAt2SoyriapPAZTvtZNL/xbYI1Gvt5jJYurPBdw=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.6.0/mode-python.min.js"
integrity="sha512-SdtfSOaR+TnSvGsZ2dmErFrcMC/CK6J/l2kNaXv3AU9BtNzqLDtK69ImVp6zOAY9Udii9GrtH7NssygOh/w0hg=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.6.0/ext-settings_menu.min.js"
integrity="sha512-GqA/hV/4FrUn8lUmY+5EWvrB4Bbw3iv0TMY4wVFLWp+OyMqhKhYWXCtYA0+X68TdEA8nUq3og+d6VLTtwprvyw=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
</head>
<body>
<button id="save_btn">Save</button>
<button id="docs_btn">Docs</button>
<button id="undo_btn">Undo</button>
<button id="redo_btn">Redo</button>
<p id="output_text">Loading</p>
<div id="code_textarea"></div>
<textarea id="code_textarea"></textarea>
<script src="/edit.js" defer=true></script>
</body>

View File

@ -1,50 +1,6 @@
let editor;
require(["ace/ace", "ace/ext/settings_menu"], function (ace) {
editor = ace.edit("code_textarea");
ace.config.set('basePath', 'https://cdnjs.cloudflare.com/ajax/libs/ace/1.6.0/');
console.log("after create editor");
console.log(editor);
editor.session.setMode("ace/mode/python");
ace.require('ace/ext/settings_menu').init(editor);
editor.commands.addCommands([{
name: "showSettingsMenu",
bindKey: {win: "Ctrl-e", mac: "Ctrl-e"},
exec: function (editor) {
console.log("ctrl-e")
editor.showSettingsMenu();
},
readOnly: true
}, {
name: "infoDocsSearch",
bindKey: {win: "Ctrl-i", mac: "Ctrl-i"},
exec: function (editor) {
window.open(`https://docs.circuitpython.org/en/latest/search.html?q=${editor.getSelectedText()}`, '_blank');
},
readOnly: true
},{
name: 'Save',
bindKey: {win: 'Ctrl-S', mac: 'Command-S'},
exec: function (editor) {
console.log("ctrl-s save");
save();
}
},{
name: "replaceCtrlR",
bindKey: {win: "Ctrl-r", mac: "Ctrl-r"},
exec: function (editor_arg) {
console.log("override ctrl r");
editor.execCommand('replace');
console.log(editor);
},
readOnly: true
}]);
});
let $editor = document.querySelector("#code_textarea");
let filename = location.hash.substring(1);
let $output_text = document.querySelector("#output_text");
/*let $code_text = document.querySelector("#code_textarea");*/
fetch(`/fs/${filename}`)
.then(function (response) {
@ -52,14 +8,14 @@ fetch(`/fs/${filename}`)
return response.status === 200 ? response.text() : "";
})
.then(function (data) {
editor.setValue(data, -1)
$editor.value = data;
});
function save() {
$output_text.innerText = "Saving..."
const requestOptions = {
method: 'PUT',
body: editor.getValue()
body: $editor.value
};
fetch(`/fs/${filename}`, requestOptions)
.then(function (response) {
@ -74,15 +30,4 @@ function save() {
document.querySelector("#save_btn").onclick = function () {
console.log("Click Save!");
save();
}
document.querySelector("#docs_btn").onclick = function () {
window.open(`https://docs.circuitpython.org/en/latest/search.html?q=${editor.getSelectedText()}`, '_blank');
}
document.querySelector("#undo_btn").onclick = function () {
editor.undo();
}
document.querySelector("#redo_btn").onclick = function () {
editor.redo();
}
}