MCPcopy Create free account
hub / github.com/Linen-dev/linen.dev / getMention

Function getMention

apps/web/ui/MessageForm/index.tsx:107–133  ·  view source on GitHub ↗
(message: string, position: number)

Source from the content-addressed store, hash-verified

105}
106
107function 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
135function isMentionKey(key: string) {
136 return ['ArrowUp', 'ArrowDown', 'Enter'].includes(key);

Callers 1

MessageFormFunction · 0.85

Calls 5

isWhitespaceFunction · 0.90
isMentionModeFunction · 0.85
isUsernameCharacterFunction · 0.85
isMentionCharacterFunction · 0.85
isUndefinedFunction · 0.85

Tested by

no test coverage detected