(message: string, position: number)
| 105 | } |
| 106 | |
| 107 | function getMention(message: string, position: number) { |
| 108 | if (isMentionMode(message, position)) { |
| 109 | const current = message[position - 1]; |
| 110 | let mention = current; |
| 111 | if (isUsernameCharacter(current)) { |
| 112 | let index = 2; |
| 113 | let character = message[position - index]; |
| 114 | while (isUsernameCharacter(character)) { |
| 115 | index++; |
| 116 | mention += character; |
| 117 | character = message[position - index]; |
| 118 | } |
| 119 | const current = character; |
| 120 | index++; |
| 121 | const previous = message[position - index]; |
| 122 | if ( |
| 123 | isMentionCharacter(current) && |
| 124 | (isWhitespace(previous) || isUndefined(previous)) |
| 125 | ) { |
| 126 | return mention.split('').reverse().join(''); |
| 127 | } |
| 128 | } else { |
| 129 | return ''; |
| 130 | } |
| 131 | } |
| 132 | return ''; |
| 133 | } |
| 134 | |
| 135 | function isMentionKey(key: string) { |
| 136 | return ['ArrowUp', 'ArrowDown', 'Enter'].includes(key); |
no test coverage detected