(input: string)
| 43 | } |
| 44 | |
| 45 | const parseSlashContext = (input: string): TriggerContext => { |
| 46 | if (!input) { |
| 47 | return { active: false, query: '', startIndex: -1 } |
| 48 | } |
| 49 | |
| 50 | const { lineStart, line } = getCurrentLineInfo(input) |
| 51 | |
| 52 | const match = line.match(/^(\s*)\/([^\s]*)$/) |
| 53 | if (!match) { |
| 54 | return { active: false, query: '', startIndex: -1 } |
| 55 | } |
| 56 | |
| 57 | const [, leadingWhitespace, commandSegment] = match |
| 58 | const startIndex = lineStart + leadingWhitespace.length |
| 59 | |
| 60 | // Slash commands only activate on the first line (startIndex must be 0) |
| 61 | if (startIndex !== 0) { |
| 62 | return { active: false, query: '', startIndex: -1 } |
| 63 | } |
| 64 | |
| 65 | return { active: true, query: commandSegment, startIndex } |
| 66 | } |
| 67 | |
| 68 | interface MentionParseResult { |
| 69 | active: boolean |
no test coverage detected