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

Function isMentionMode

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

Source from the content-addressed store, hash-verified

71}
72
73function 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
103function getMode(message: string, position: number) {
104 return isMentionMode(message, position) ? Mode.Mention : Mode.Standard;

Callers 2

getModeFunction · 0.85
getMentionFunction · 0.85

Calls 4

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

Tested by

no test coverage detected