返回 DeepSeek-Reasonix
refToken.ts
根目录 / desktop / frontend / src / lib / refToken.ts
1 // refToken mirrors the Go @-token grammar in internal/control/refs.go: a token
2 // is a run of non-whitespace, except that a backslash-escaped space or tab
3 // stays inside the token. Any other backslash is literal so Windows separators
4 // keep their meaning. escapeRefPath/unescapeRefPath are the inverse pair the
5 // control layer applies when resolving refs on submit.
6
7 // One token character: an escaped space/tab pair, or any non-whitespace byte.
8 const TOKEN_CHAR = String.raw`(?:\\[ \t]|[^\s])`;
9
10 // The @token ending at the cursor (token may be empty while still typing).
11 export const activeRefTokenRe = new RegExp(`(?:^|\\s)@(${TOKEN_CHAR}*)$`);
12
13 // All @tokens in a text, for display badge extraction.
14 export function refTokenRe(): RegExp {
15 return new RegExp(`(^|\\s)@(${TOKEN_CHAR}+)`, "g");
16 }
17
18 export function escapeRefPath(path: string): string {
19 return path.replace(/[ \t]/g, (ws) => "\\" + ws);
20 }
21
22 export function unescapeRefPath(token: string): string {
23 return token.replace(/\\([ \t])/g, "$1");
24 }
25
25 lines TYPESCRIPT