Skip to content

Conversation

@johndoknjas
Copy link
Contributor

Closes #12425.

const newVal = prefix + chatInput.value;
chatInput.focus();
chatInput.select();
if (!document.execCommand('insertText', false, newVal)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

document.execCommand is deprecated

Copy link
Contributor Author

@johndoknjas johndoknjas Mar 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few alternatives but none are fully ideal (since there's no direct replacement yet for execCommand):

  1. Just use the code I have inside that if block. The only problem is if the user then does ctrl+z, the '@username' won't be removed.
  2. Use a third party library (instead of execCommand) to mimic user input so that the '@username' is included in the browser's ctrl+z stack.

const newVal = prefix + chatInput.value;
if (!chatInput.value.startsWith(prefix)) chatInput.value = prefix + chatInput.value;
chatInput.focus();
chatInput.select();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure what that was for? didn't seem useful to me to have the entire input text selected.

I might be missing something

instead, guess the username from the link in the chat line
@ornicar ornicar merged commit 32b1f29 into lichess-org:master Mar 24, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reply Button in Tournament/Broadcast/Team chats

2 participants