add based option for ace editor that copies on empty selection

This commit is contained in:
Mikkel Kongsted 2025-10-11 22:58:56 +02:00
parent 4a647a3f26
commit 43133d67e9

View File

@ -55,6 +55,7 @@ const langTools = ace.require("ace/ext/language_tools");
editor.setOptions({
enableBasicAutocompletion: true,
enableLiveAutocompletion: true,
copyWithEmptySelection: true,
});
langTools.setCompleters([new GamelibCompleter(), new TextCompleter()]);
@ -221,42 +222,3 @@ saveKarlkoderButton.onclick = () => {
};
toggleSpriteEditorButton.addEventListener("click", () => spriteEditor.toggleEditor());
consoleInput.onkeydown = (ev) => {
if (ev.key !== "Enter") return;
const code = ev.target.value;
ev.target.value = "";
codeRunner.evaluateCode(code);
};
editor.commands.addCommand({
name: "cut",
bindKey: { win: "Ctrl-X" },
exec: function (editor) {
const cutLine = editor.selection.isEmpty();
const range = cutLine ? editor.selection.getLineRange() : editor.selection.getRange();
editor._emit("cut", range);
if (!range.isEmpty()) {
editor.session.remove(range);
}
editor.clearSelection();
},
scrollIntoView: "cursor",
multiSelectAction: "forEach",
readOnly: false,
});
function copy(text) {
const elem = document.createElement("input");
elem.value = text;
elem.display = "none";
document.body.appendChild(elem);
elem.select();
document.execCommand("copy");
requestAnimationFrame(() => elem.remove());
}