(text: string, position: number)
| 76 | } |
| 77 | |
| 78 | export function removeMention(text: string, position: number): { newText: string; newPosition: number } { |
| 79 | const beforeCursor = text.slice(0, position) |
| 80 | const afterCursor = text.slice(position) |
| 81 | |
| 82 | // Check if we're at the end of a mention |
| 83 | const matchEnd = beforeCursor.match(new RegExp(mentionRegex.source + "$")) |
| 84 | |
| 85 | if (matchEnd) { |
| 86 | // If we're at the end of a mention, remove it |
| 87 | // Remove the mention and the first space that follows it |
| 88 | const mentionLength = matchEnd[0].length |
| 89 | // Remove the mention and one space after it if it exists |
| 90 | const newText = text.slice(0, position - mentionLength) + afterCursor.replace(/^\s/, "") |
| 91 | const newPosition = position - mentionLength |
| 92 | return { newText, newPosition } |
| 93 | } |
| 94 | |
| 95 | // If we're not at the end of a mention, just return the original text and position |
| 96 | return { newText: text, newPosition: position } |
| 97 | } |
| 98 | |
| 99 | export enum ContextMenuOptionType { |
| 100 | OpenedFile = "openedFile", |
no test coverage detected