diff --git a/editmode.ts b/editmode.ts index 490db61..0b41990 100644 --- a/editmode.ts +++ b/editmode.ts @@ -8,6 +8,7 @@ import { K, getKeyboardString, keyPressed, shiftKeyDown } from "./keyboard.ts"; // deno-lint-ignore prefer-const let tab: "code" | "sprite" | "map" | "sfx" | "music" = "code"; +// TODO: Make scrolling work const codeTabState = { scrollX: 0, scrollY: 0, @@ -139,6 +140,7 @@ const drawCodeField = (code: string, x: number, y: number, w: number, h: number) if (anchor === focus) { fillRect(x+focusX*fontWidth-scrollX, y+focusY*(fontHeight+1)-scrollY, fontWidth+1, fontHeight+1, COLOR.RED); } else { + // TODO: Draw this selection better fillRect(x+anchorX*fontWidth-scrollX, y+anchorY*(fontHeight+1)-scrollY, fontWidth+1, fontHeight+1, COLOR.GREEN); fillRect(x+focusX*fontWidth-scrollX, y+focusY*(fontHeight+1)-scrollY, fontWidth+1, fontHeight+1, COLOR.YELLOW); } @@ -154,7 +156,11 @@ const update = () => { if (keyboardString) { codeTabState.insertText(keyboardString); } + // TODO: Handle ctrl-C, ctrl-V, ctrl-X, ctrl-Z + // TODO: Make ctrl-/ do commenting out (take inspiration from tab) + if (keyPressed(K.ENTER)) { + // TODO: Make this play nicely with indentation codeTabState.insertText("\n"); } if (keyPressed(K.TAB)) { diff --git a/keyboard.ts b/keyboard.ts index 0e16d79..d4e2906 100644 --- a/keyboard.ts +++ b/keyboard.ts @@ -115,6 +115,10 @@ export const shiftKeyDown = () => { return keyDown(K.SHIFT_LEFT) || keyDown(K.SHIFT_RIGHT); } +export const ctrlKeyDown = () => { + return keyDown(K.CTRL_LEFT) || keyDown(K.CTRL_RIGHT); +} + export const keyReleased = (key: string | number) => { if (typeof key === "string") { key = key.toUpperCase().charCodeAt(0); @@ -131,6 +135,9 @@ export const getKeysPressed = () => { export const getKeyboardString = () => { let str = ""; + if (ctrlKeyDown()) { + return str; + } for (const key of getKeysPressed()) { let char = String.fromCharCode(key).toLowerCase(); if (shiftKeyDown()) {