({delegateTarget: button}: DelegateEvent)
| 40 | } |
| 41 | |
| 42 | function mentionUser({delegateTarget: button}: DelegateEvent): void { |
| 43 | const userMention = getCommentAuthor(button.parentElement!); |
| 44 | const newComment = $(fieldSelector); |
| 45 | newComment.focus(); |
| 46 | |
| 47 | // If the new comment field has selected text, don’t replace it |
| 48 | newComment.selectionStart = newComment.selectionEnd; |
| 49 | |
| 50 | // If the cursor is preceded by a space (or is at place 0), don't add a space before the mention |
| 51 | const precedingCharacter = newComment.value.slice(newComment.selectionStart - 1, newComment.selectionStart); |
| 52 | const spacer = /\s|^$/.test(precedingCharacter) ? '' : ' '; |
| 53 | |
| 54 | // The space after closes the autocomplete box and places the cursor where the user would start typing |
| 55 | insertTextIntoField(newComment, `${spacer}${prefixUserMention(userMention)} `); |
| 56 | } |
| 57 | |
| 58 | function addButton(avatar: HTMLElement): void { |
| 59 | const userMention = getCommentAuthor(avatar); |
nothing calls this directly
no test coverage detected