You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/shared/context-mentions.ts
+16-9Lines changed: 16 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,25 @@
1
1
/*
2
2
Mention regex:
3
-
- **Purpose**:
4
-
- To identify and highlight specific mentions in text that start with '@'.
3
+
- **Purpose**:
4
+
- To identify and highlight specific mentions in text that start with '@'.
5
5
- These mentions can be file paths, URLs, or the exact word 'problems'.
6
6
- Ensures that trailing punctuation marks (like commas, periods, etc.) are not included in the match, allowing punctuation to follow the mention without being part of it.
7
+
- Restricts @ parsing to line-start or after whitespace to avoid accidental loading from pasted logs.
7
8
8
9
- **Regex Breakdown**:
9
-
- `/@`:
10
+
- `(?:^|\s)`:
11
+
- **Non-Capturing Group (`(?:...)`)**: Groups the alternatives without capturing them.
12
+
- **Line Start or Whitespace (`^|\s`)**: The @ must be at the start of a line or preceded by whitespace.
13
+
14
+
- `(?<!\\)@`:
15
+
- **Negative Lookbehind (`(?<!\\)`)**: Ensures the @ is not escaped with a backslash.
10
16
- **@**: The mention must start with the '@' symbol.
- **Capturing Group (`(...)`)**: Captures the part of the string that matches one of the specified patterns.
14
-
- `(?:\/|\w+:\/\/)`:
20
+
- `(?:\/|\w+:\/\/)`:
15
21
- **Non-Capturing Group (`(?:...)`)**: Groups the alternatives without capturing them for back-referencing.
16
-
- `\/`:
22
+
- `\/`:
17
23
- **Slash (`/`)**: Indicates that the mention is a file or folder path starting with a '/'.
18
24
- `|`: Logical OR.
19
25
- `\w+:\/\/`:
@@ -25,7 +31,7 @@ Mention regex:
25
31
- **Escaped Space (`\\ `)**: Matches a backslash followed by a space (an escaped space).
26
32
- **Non-Greedy (`+?`)**: Ensures the smallest possible match, preventing the inclusion of trailing punctuation.
27
33
- `|`: Logical OR.
28
-
- `problems\b`:
34
+
- `problems\b`:
29
35
- **Exact Word ('problems')**: Matches the exact word 'problems'.
30
36
- **Word Boundary (`\b`)**: Ensures that 'problems' is matched as a whole word and not as part of another word (e.g., 'problematic').
31
37
- `|`: Logical OR.
@@ -34,9 +40,9 @@ Mention regex:
34
40
- **Word Boundary (`\b`)**: Ensures that 'terminal' is matched as a whole word and not as part of another word (e.g., 'terminals').
35
41
- `(?=[.,;:!?]?(?=[\s\r\n]|$))`:
36
42
- **Positive Lookahead (`(?=...)`)**: Ensures that the match is followed by specific patterns without including them in the match.
37
-
- `[.,;:!?]?`:
43
+
- `[.,;:!?]?`:
38
44
- **Optional Punctuation (`[.,;:!?]?`)**: Matches zero or one of the specified punctuation marks.
39
-
- `(?=[\s\r\n]|$)`:
45
+
- `(?=[\s\r\n]|$)`:
40
46
- **Nested Positive Lookahead (`(?=[\s\r\n]|$)`)**: Ensures that the punctuation (if present) is followed by a whitespace character, a line break, or the end of the string.
41
47
42
48
- **Summary**:
@@ -48,13 +54,14 @@ Mention regex:
48
54
- The exact word 'git-changes'.
49
55
- The exact word 'terminal'.
50
56
- It ensures that any trailing punctuation marks (such as ',', '.', '!', etc.) are not included in the matched mention, allowing the punctuation to follow the mention naturally in the text.
57
+
- **NEW**: The @ symbol must be at the start of a line or preceded by whitespace to prevent accidental matches in pasted logs.
51
58
52
59
- **Global Regex**:
53
60
- `mentionRegexGlobal`: Creates a global version of the `mentionRegex` to find all matches within a given string.
0 commit comments