From b9922b3bdc8cce55db4b1c0d2af3f854ca62b041 Mon Sep 17 00:00:00 2001 From: orion Date: Mon, 29 Jun 2026 06:40:39 +0200 Subject: [PATCH] Custom Input Module Working mostly accurately --- src/modules/terminal/Input.svelte | 65 ++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 23 deletions(-) diff --git a/src/modules/terminal/Input.svelte b/src/modules/terminal/Input.svelte index b6660f7..deed865 100644 --- a/src/modules/terminal/Input.svelte +++ b/src/modules/terminal/Input.svelte @@ -3,7 +3,7 @@ let { value = $bindable(''), - blinkDelay = 500, + blinkDelay = 250, autofocus = true, oninput = () => {} }: { @@ -15,18 +15,11 @@ let container: HTMLDivElement | undefined; let cursorPos: number = $derived(value.length); - let text: string = $derived(value); + let text: string = $state(''); let focused: boolean = $state(false); let blinkPaused: boolean = $state(false); // true → cursor steady, false → blinking let blinkTimer: ReturnType | null = null; - $effect(() => { - if (value !== text) { - text = value; - cursorPos = Math.min(cursorPos, text.length); - } - }); - $effect(() => { if (autofocus && container) { container.focus(); @@ -52,11 +45,14 @@ } function handleFocus() { + console.log('focused'); focused = true; blinkPaused = false; // start blinking immediately } function handleBlur() { + console.log('blured'); + focused = false; if (blinkTimer) { clearTimeout(blinkTimer); @@ -95,7 +91,8 @@ } function handleKeydown(e: KeyboardEvent) { - // Ctrl + A / Ctrl + E + console.log(e.key); + if (e.ctrlKey) { if (e.key === 'a' || e.key === 'A') { e.preventDefault(); @@ -109,6 +106,24 @@ pauseBlink(); return; } + if (e.key === 'd' || e.key === 'D') { + e.preventDefault(); + deleteCharAfter(); + return; + } + + if (e.key === 'ArrowLeft') { + e.preventDefault(); + cursorPos = 0; + pauseBlink(); + return; + } + if (e.key === 'ArrowRight') { + e.preventDefault(); + cursorPos = text.length; + pauseBlink(); + return; + } // ignore other Ctrl combos return; } @@ -158,7 +173,7 @@ return; } - // Everything else (Enter, Tab, etc.) is ignored. + // Everything else (Enter, Tab, etc.) is ignored.EEE } onMount(() => { @@ -170,7 +185,7 @@
- $ -
\ No newline at end of file +
+ + +