From 19d194a611550ffb65d3ac3d7d7d976ce22307cb Mon Sep 17 00:00:00 2001 From: Marcel Schramm Date: Wed, 25 Dec 2024 14:19:01 +0100 Subject: [PATCH] Frontend message input arrow up now places cursor at the end --- internal/frontend/lobby.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/internal/frontend/lobby.js b/internal/frontend/lobby.js index ef7b9e8c..16d1cbf6 100644 --- a/internal/frontend/lobby.js +++ b/internal/frontend/lobby.js @@ -780,6 +780,14 @@ messageInput.addEventListener("keypress", sendMessage); messageInput.addEventListener("keydown", function(event) { if (event.code === 'ArrowUp' && messageInput.value.length === 0) { messageInput.value = lastMessage; + const length = lastMessage.length; + // Postpone selection change onto next event queue loop iteration, as + // nothing will happen otherwise. + setTimeout(() => { + // length+1 is necessary, as the selection wont change if start and + // end are the same, + messageInput.setSelectionRange(length + 1, length); + }, 0); } });