From 5d9c113eea38a5e2b616604dc6821082368cf76b Mon Sep 17 00:00:00 2001 From: Frank Date: Sat, 22 Aug 2026 17:32:00 +0200 Subject: [PATCH] Recall the last command with ArrowUp in the game terminal Pressing ArrowUp while the input field is focused now repopulates it with the last submitted command, cursor placed at the end. Co-Authored-By: Claude Sonnet 5 --- assets/game1.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/assets/game1.js b/assets/game1.js index b02d800..3e9f18b 100644 --- a/assets/game1.js +++ b/assets/game1.js @@ -418,6 +418,17 @@ document.addEventListener('DOMContentLoaded', async () => { const inputField = document.getElementById('input-message'); inputField.disabled = false; + let lastCommand = ''; + + // Recall the last submitted command on ArrowUp, cursor at the end + inputField.addEventListener('keydown', (e) => { + if (e.key === 'ArrowUp') { + e.preventDefault(); + inputField.value = lastCommand; + inputField.setSelectionRange(inputField.value.length, inputField.value.length); + } + }); + // Add event listener for Enter key inputField.addEventListener('keypress', async (e) => { if (e.key === 'Enter') { @@ -431,6 +442,7 @@ document.addEventListener('DOMContentLoaded', async () => { messageContainer.appendChild(msgEl); if (message && apiEchoUrl) { + lastCommand = message; inputField.value = ''; try { const response = await fetchJson(apiEchoUrl, {