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 <noreply@anthropic.com>
This commit is contained in:
@@ -418,6 +418,17 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||||||
const inputField = document.getElementById('input-message');
|
const inputField = document.getElementById('input-message');
|
||||||
inputField.disabled = false;
|
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
|
// Add event listener for Enter key
|
||||||
inputField.addEventListener('keypress', async (e) => {
|
inputField.addEventListener('keypress', async (e) => {
|
||||||
if (e.key === 'Enter') {
|
if (e.key === 'Enter') {
|
||||||
@@ -431,6 +442,7 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||||||
messageContainer.appendChild(msgEl);
|
messageContainer.appendChild(msgEl);
|
||||||
|
|
||||||
if (message && apiEchoUrl) {
|
if (message && apiEchoUrl) {
|
||||||
|
lastCommand = message;
|
||||||
inputField.value = '';
|
inputField.value = '';
|
||||||
try {
|
try {
|
||||||
const response = await fetchJson(apiEchoUrl, {
|
const response = await fetchJson(apiEchoUrl, {
|
||||||
|
|||||||
Reference in New Issue
Block a user