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
+17-16Lines changed: 17 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -1,28 +1,29 @@
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
7
8
8
- **Regex Breakdown**:
9
-
- `/@`:
9
+
- `/@`:
10
10
- **@**: The mention must start with the '@' symbol.
- **Capturing Group (`(...)`)**: Captures the part of the string that matches one of the specified patterns.
14
-
- `(?:\/|\w+:\/\/)`:
14
+
- `(?:\/|\w+:\/\/)`:
15
15
- **Non-Capturing Group (`(?:...)`)**: Groups the alternatives without capturing them for back-referencing.
16
-
- `\/`:
16
+
- `\/`:
17
17
- **Slash (`/`)**: Indicates that the mention is a file or folder path starting with a '/'.
18
18
- `|`: Logical OR.
19
-
- `\w+:\/\/`:
19
+
- `\w+:\/\/`:
20
20
- **Protocol (`\w+://`)**: Matches URLs that start with a word character sequence followed by '://', such as 'http://', 'https://', 'ftp://', etc.
21
-
- `[^\s]+?`:
22
-
- **Non-Whitespace Characters (`[^\s]+`)**: Matches one or more characters that are not whitespace.
21
+
- `(?:[^\s]|\s(?=[^\s]))+?`:
22
+
- **Character Pattern**: Matches either a non-whitespace character OR a whitespace character that is followed by a non-whitespace character.
23
+
- **This allows spaces within file paths while preventing trailing spaces**.
23
24
- **Non-Greedy (`+?`)**: Ensures the smallest possible match, preventing the inclusion of trailing punctuation.
24
25
- `|`: Logical OR.
25
-
- `problems\b`:
26
+
- `problems\b`:
26
27
- **Exact Word ('problems')**: Matches the exact word 'problems'.
27
28
- **Word Boundary (`\b`)**: Ensures that 'problems' is matched as a whole word and not as part of another word (e.g., 'problematic').
28
29
- `|`: Logical OR.
@@ -31,14 +32,14 @@ Mention regex:
31
32
- **Word Boundary (`\b`)**: Ensures that 'terminal' is matched as a whole word and not as part of another word (e.g., 'terminals').
32
33
- `(?=[.,;:!?]?(?=[\s\r\n]|$))`:
33
34
- **Positive Lookahead (`(?=...)`)**: Ensures that the match is followed by specific patterns without including them in the match.
34
-
- `[.,;:!?]?`:
35
+
- `[.,;:!?]?`:
35
36
- **Optional Punctuation (`[.,;:!?]?`)**: Matches zero or one of the specified punctuation marks.
36
-
- `(?=[\s\r\n]|$)`:
37
+
- `(?=[\s\r\n]|$)`:
37
38
- **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.
38
-
39
+
39
40
- **Summary**:
40
41
- The regex effectively matches:
41
-
- Mentions that are file or folder paths starting with '/' and containing any non-whitespace characters (including periods within the path).
42
+
- Mentions that are file or folder paths starting with '/' and can contain spaces within the path (e.g., 'my folder/my file.txt').
42
43
- URLs that start with a protocol (like 'http://') followed by any non-whitespace characters (including query parameters).
0 commit comments