async function setupEditor() {
		const Emmet = ace.require("ace/ext/emmet");
		const textInput = editor.textInput.getElement();
		const settings = appSettings.value;
		const { leftMargin, textWrap, colorPreview, fontSize, lineHeight } =
			appSettings.value;
		const scrollMarginTop = 0;
		const scrollMarginLeft = 0;
		const scrollMarginRight = textWrap ? 0 : leftMargin;
		const scrollMarginBottom = 0;

		let checkTimeout = null;
		let autosaveTimeout;
		let scrollTimeout;

		editor.on("focus", async () => {
			const { activeFile } = manager;
			activeFile.focused = true;
			keyboardHandler.on("keyboardShow", scrollCursorIntoView);

			if (isScrolling) return;

			$hScrollbar.hide();
			$vScrollbar.hide();
		});

		editor.on("blur", async () => {
			const { hardKeyboardHidden, keyboardHeight } =
				await getSystemConfiguration();
			const blur = () => {
				const { activeFile } = manager;
				activeFile.focused = false;
				activeFile.focusedBefore = false;
			};

			if (
				hardKeyboardHidden === HARDKEYBOARDHIDDEN_NO &&
				keyboardHeight < 100
			) {
				// external keyboard
				blur();
				return;
			}

			const onKeyboardHide = () => {
				keyboardHandler.off("keyboardHide", onKeyboardHide);
				blur();
			};

			keyboardHandler.on("keyboardHide", onKeyboardHide);
		});

		editor.on("change", (e) => {
			if (checkTimeout) clearTimeout(checkTimeout);
			if (autosaveTimeout) clearTimeout(autosaveTimeout);

			checkTimeout = setTimeout(async () => {
				const { activeFile } = manager;

				if (activeFile.markChanged) {
					const changed = await activeFile.isChanged();
					activeFile.isUnsaved = changed;
					activeFile.writeToCache();
					events.emit("file-content-changed", activeFile);
					manager.onupdate("file-changed");
					manager.emit("update", "file-changed");

					const { autosave } = appSettings.value;
					if (activeFile.uri && changed && autosave) {
						autosaveTimeout = setTimeout(() => {
							acode.exec("save", false);
						}, autosave);
					}
				}
				activeFile.markChanged = true;
			}, TIMEOUT_VALUE);
		});

		editor.on("changeAnnotation", toggleProblemButton);

		editor.on("scroll", () => {
			clearTimeout(scrollTimeout);
			isScrolling = true;
			scrollTimeout = setTimeout(() => {
				isScrolling = false;
			}, 100);
		});

		editor.renderer.on("resize", () => {
			$vScrollbar.resize($vScrollbar.visible);
			$hScrollbar.resize($hScrollbar.visible);
		});

		editor.on("scrolltop", onscrolltop);
		editor.on("scrollleft", onscrollleft);
		textInput.addEventListener("keydown", (e) => {
			if (e.key === "Escape") {
				keydownState.esc = { value: true, target: textInput };
			}
		});

		if (colorPreview) {
			initColorView(editor);
		}

		touchListeners(editor);
		setCommands(editor);
		await setKeyBindings(editor);
		Emmet.setCore(window.emmet);
		editor.setFontSize(fontSize);
		editor.setHighlightSelectedWord(true);
		editor.container.style.lineHeight = lineHeight;

		ace.require("ace/ext/language_tools");
		editor.setOption("animatedScroll", false);
		editor.setOption("tooltipFollowsMouse", false);
		editor.setOption("theme", settings.editorTheme);
		editor.setOption(
			"showGutter",
			settings.linenumbers || settings.showAnnotations,
		);
		editor.setOption("showLineNumbers", settings.linenumbers);
		editor.setOption("enableEmmet", true);
		editor.setOption("showInvisibles", settings.showSpaces);
		editor.setOption("indentedSoftWrap", false);
		editor.setOption("scrollPastEnd", 0.5);
		editor.setOption("showPrintMargin", settings.showPrintMargin);
		editor.setOption("relativeLineNumbers", settings.relativeLineNumbers);
		editor.setOption("useElasticTabstops", settings.elasticTabstops);
		editor.setOption("useTextareaForIME", settings.useTextareaForIME);
		editor.setOption("rtlText", settings.rtlText);
		editor.setOption("hardWrap", settings.hardWrap);
		editor.setOption("spellCheck", settings.spellCheck);
		editor.setOption("printMarginColumn", settings.printMargin);
		editor.setOption("enableBasicAutocompletion", true);
		editor.setOption("enableLiveAutocompletion", settings.liveAutoCompletion);
		editor.setOption("copyWithEmptySelection", true);
		editor.setOption("fadeFoldWidgets", settings.fadeFoldWidgets);
		// editor.setOption('enableInlineAutocompletion', settings.inlineAutoCompletion);

		updateMargin(true);
		updateSideButtonContainer();
		editor.renderer.setScrollMargin(
			scrollMarginTop,
			scrollMarginBottom,
			scrollMarginLeft,
			scrollMarginRight,
		);
	}
Sets up the editor with various configurations and event listeners.
@returns {Promise<void>} A promise that resolves once the editor is set up.