mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-22 23:53:48 +01:00
added beautifier button in text editor
This commit is contained in:
parent
ec862ec747
commit
c35395e302
@ -1,4 +1,5 @@
|
|||||||
var ace = require('brace');
|
var ace = require('brace');
|
||||||
|
var beautify = require('js-beautify').js_beautify;
|
||||||
require('brace/mode/javascript');
|
require('brace/mode/javascript');
|
||||||
require('../netscript');
|
require('../netscript');
|
||||||
require('brace/theme/chaos');
|
require('brace/theme/chaos');
|
||||||
@ -57,6 +58,15 @@ function scriptEditorInit() {
|
|||||||
console.log("Error finding 'script-editor-buttons-wrapper'");
|
console.log("Error finding 'script-editor-buttons-wrapper'");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
var beautifyButton = createElement("a", {
|
||||||
|
class:"a-link-button", display:"inline-block",
|
||||||
|
innerText:"beautify",
|
||||||
|
clickListener:()=>{
|
||||||
|
beautifyScript();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
var closeButton = createElement("a", {
|
var closeButton = createElement("a", {
|
||||||
class:"a-link-button", display:"inline-block",
|
class:"a-link-button", display:"inline-block",
|
||||||
innerText:"Save & Close (Ctrl/Cmd + b)",
|
innerText:"Save & Close (Ctrl/Cmd + b)",
|
||||||
@ -90,6 +100,7 @@ function scriptEditorInit() {
|
|||||||
target:"_blank"
|
target:"_blank"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
wrapper.appendChild(beautifyButton);
|
||||||
wrapper.appendChild(closeButton);
|
wrapper.appendChild(closeButton);
|
||||||
wrapper.appendChild(scriptEditorRamText);
|
wrapper.appendChild(scriptEditorRamText);
|
||||||
wrapper.appendChild(scriptEditorRamCheck);
|
wrapper.appendChild(scriptEditorRamCheck);
|
||||||
@ -243,6 +254,13 @@ $(document).keydown(function(e) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function beautifyScript() {
|
||||||
|
var editor = ace.edit('javascript-editor');
|
||||||
|
var code = editor.getValue();
|
||||||
|
code = beautify(code, { indent_size: 4 })
|
||||||
|
editor.setValue(code);
|
||||||
|
}
|
||||||
|
|
||||||
function saveAndCloseScriptEditor() {
|
function saveAndCloseScriptEditor() {
|
||||||
var filename = document.getElementById("script-editor-filename").value;
|
var filename = document.getElementById("script-editor-filename").value;
|
||||||
var editor = ace.edit('javascript-editor');
|
var editor = ace.edit('javascript-editor');
|
||||||
|
Loading…
Reference in New Issue
Block a user