Skip to content

Commit f986875

Browse files
committed
DUnno
1 parent a77fdfc commit f986875

File tree

11 files changed

+2181
-8655
lines changed

11 files changed

+2181
-8655
lines changed

build/editor/editor.html

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,6 @@ <h3 class="panel-title">Script Resources</h3>
321321
<button type="button" class="toolbar-btn" id="settingsBtn" title="Editor settings">
322322
<i data-feather="settings"></i>
323323
</button>
324-
<button type="button" class="toolbar-btn" id="formatBtn" title="Format code (Alt+F)">
325-
<i data-feather="align-left"></i>
326-
Format
327-
</button>
328324
</div>
329325
<div class="toolbar-info">
330326
<span id="cursorInfo" class="cursor-info">Line 1, Column 1</span>

build/editor/editor.js

Lines changed: 813 additions & 5693 deletions
Large diffs are not rendered by default.

build/editor/editor_managers.js

Lines changed: 740 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@ import { EditorView, keymap, lineNumbers, gutter } from "@codemirror/view";
33
import { basicSetup } from "codemirror";
44
import { javascript } from "@codemirror/lang-javascript";
55
import { defaultKeymap, indentWithTab } from "@codemirror/commands";
6-
import { parseUserScriptMetadata } from './metadataParser.js';
6+
import { parseUserScriptMetadata } from '../utils/metadataParser.js';
77
import { autocompletion, closeBrackets } from "@codemirror/autocomplete";
88
import { bracketMatching, foldGutter } from "@codemirror/language";
99
import { linter, lintGutter } from "@codemirror/lint";
10-
import { js_beautify } from 'js-beautify';
1110
import { showMinimap } from '@replit/codemirror-minimap';
1211
import { oneDark } from '@codemirror/theme-one-dark';
1312

@@ -183,7 +182,6 @@ export class CodeEditorManager {
183182
indentWithTab,
184183
{ key: "Ctrl-s", run: () => { this.onSaveCallback?.(); return true; } },
185184
{ key: "Cmd-s", run: () => { this.onSaveCallback?.(); return true; } },
186-
{ key: "Alt-f", run: () => { this.formatCode(true); return true; } },
187185
{ key: "F11", run: (view) => {
188186
if (view.dom.requestFullscreen) {
189187
view.dom.requestFullscreen();
@@ -386,40 +384,6 @@ export class CodeEditorManager {
386384
return this.state.lintingEnabled;
387385
}
388386

389-
async formatCode(showMessage = true, onFormatComplete) {
390-
try {
391-
if (!this.codeEditor) {
392-
throw new Error("Code editor not initialized");
393-
}
394-
395-
const unformattedCode = this.getValue();
396-
const formattedCode = js_beautify(unformattedCode, {
397-
indent_size: 2,
398-
space_in_empty_paren: true,
399-
});
400-
401-
this.setValue(formattedCode);
402-
403-
if (showMessage && this.onStatusCallback) {
404-
this.onStatusCallback("Code formatted", "success");
405-
setTimeout(
406-
() => this.onStatusCallback(null),
407-
this.config.STATUS_TIMEOUT
408-
);
409-
}
410-
411-
if (typeof onFormatComplete === 'function') {
412-
await onFormatComplete();
413-
}
414-
} catch (error) {
415-
console.error("Error formatting code:", error);
416-
if (showMessage && this.onStatusCallback) {
417-
this.onStatusCallback("Could not format code", "error");
418-
}
419-
return false;
420-
}
421-
}
422-
423387
insertTemplateCode(template) {
424388
const wrappedCode = `(function() {
425389
'use strict';
@@ -428,7 +392,6 @@ export class CodeEditorManager {
428392
429393
})();`;
430394
this.setValue(wrappedCode);
431-
this.formatCode(false);
432395
}
433396

434397
insertDefaultTemplate() {
@@ -441,7 +404,6 @@ export class CodeEditorManager {
441404
})();`;
442405

443406
this.setValue(defaultCode);
444-
this.formatCode(false);
445407
}
446408

447409
getValue() {

0 commit comments

Comments
 (0)