(message: string, position: number)
| 71 | } |
| 72 | |
| 73 | function isMentionMode(message: string, position: number) { |
| 74 | const current = message[position - 1]; |
| 75 | const previous = message[position - 2]; |
| 76 | if ( |
| 77 | isMentionCharacter(current) && |
| 78 | (isWhitespace(previous) || isUndefined(previous)) |
| 79 | ) { |
| 80 | return true; |
| 81 | } |
| 82 | |
| 83 | if (isUsernameCharacter(current)) { |
| 84 | let index = 2; |
| 85 | let character = message[position - index]; |
| 86 | while (isUsernameCharacter(character)) { |
| 87 | index++; |
| 88 | character = message[position - index]; |
| 89 | } |
| 90 | const current = character; |
| 91 | index++; |
| 92 | const previous = message[position - index]; |
| 93 | if ( |
| 94 | isMentionCharacter(current) && |
| 95 | (isWhitespace(previous) || isUndefined(previous)) |
| 96 | ) { |
| 97 | return true; |
| 98 | } |
| 99 | } |
| 100 | return false; |
| 101 | } |
| 102 | |
| 103 | function getMode(message: string, position: number) { |
| 104 | return isMentionMode(message, position) ? Mode.Mention : Mode.Standard; |
no test coverage detected