Skip to content

Commit

Permalink
1.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Posney committed Oct 30, 2023
1 parent a399aa0 commit 1bdb328
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 1.0.2
* update module.json
* add ability to change editor default window size from settings.

### 1.0.1
* remove some debug

Expand Down
2 changes: 1 addition & 1 deletion dist/module.js

Large diffs are not rendered by default.

15 changes: 7 additions & 8 deletions src/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function updateActiveEditors<T extends keyof NewOptionsType>(
}
}

export let registerTypes = (_: string, __: string): void => {};
export let registerTypes = (_: string, __: string): void => { };

export async function setupMonaco() {
// make sure that process.env exists before initializing monaco
Expand Down Expand Up @@ -68,7 +68,7 @@ export async function setupMonaco() {
esModuleInterop: true,
});

if(settings.loadTypesImmediately) {
if (settings.loadTypesImmediately) {
Hooks.callAll("monaco-editor.ready", registerTypes);
}
}
Expand All @@ -77,9 +77,9 @@ let typesLoaded = false
let monacoLoaded = false

export async function attachMonacoEditor(form: HTMLFormElement) {
if(!monacoLoaded) {
// settings is not available all the time so we need to do this in fairly dumb way
if(!settings.delayedLoading) {
if (!monacoLoaded) {
// settings is not available all the time so we need to do this in fairly dumb way
if (!settings.delayedLoading) {
monacoLoaded = true
} else {
await setupMonaco()
Expand All @@ -93,7 +93,7 @@ export async function attachMonacoEditor(form: HTMLFormElement) {
".form-group.command"
);

if(!typesLoaded) {
if (!typesLoaded) {
typesLoaded = true
Hooks.callAll("monaco-editor.ready", registerTypes);
}
Expand All @@ -110,7 +110,7 @@ export async function attachMonacoEditor(form: HTMLFormElement) {
const select: HTMLSelectElement = form.querySelector('select[name="type"]')!;

commandLabel.insertAdjacentElement("beforeend", div);

const editor = monaco.editor.create(div, {
// editor specific
value: oldTextArea.value,
Expand All @@ -129,7 +129,6 @@ export async function attachMonacoEditor(form: HTMLFormElement) {
theme: settings.theme,
fontSize: settings.fontSize,
});

activeEditors.add(editor);

editor.onDidChangeModelContent(
Expand Down
12 changes: 11 additions & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,17 @@ Hooks.on("monaco-editor.ready", async (register: typeof registerTypes) => {
}
});

Hooks.on("renderMacroConfig", ({ form }: { form: HTMLFormElement }) => {
Hooks.on("renderMacroConfig", (app: any, html: any, data: any) => {
let { form } = app;
const windowSizes = {
"small": { width: 900, height: 650 },
"medium": { width: 1500, height: 1000 },
"large": { width: 1800, height: 1200 }
}
//@ts-expect-error
const size: any = windowSizes[settings.windowSize] ?? "medium";
console.error("Size is ", size, settings.windowSize );
app.setPosition(size);
if (settings.enableMonacoEditor) {
bailOnMacroEditor()
furnaceFix(form);
Expand Down
10 changes: 10 additions & 0 deletions src/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Settings = {
enableMonacoEditor: boolean;
loadTypesImmediately: boolean;
delayedLoading: boolean;
windowSize: string;
};

/**
Expand All @@ -39,6 +40,15 @@ export function registerSettings() {
},
});

defineSetting("windowSize", {
default: "medium",
choices: {
"small": "900 x 650",
"medium": "1500 x 1000",
"large": "1800 x 1200"
},
});

defineSetting("delayedLoading", {
hint: "Delay the loading of the monaco editor until the first editor is opened",
default: true,
Expand Down

0 comments on commit 1bdb328

Please sign in to comment.