Skip to content

Commit

Permalink
Frontend message input arrow up now places cursor at the end
Browse files Browse the repository at this point in the history
  • Loading branch information
Bios-Marcel committed Dec 25, 2024
1 parent 0c19fe0 commit 19d194a
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/frontend/lobby.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});

Expand Down

0 comments on commit 19d194a

Please sign in to comment.