-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
feat(search): syntax highlight regex literals #125664
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JoshuaKGoldberg
merged 10 commits into
master
from
joshgoldberg/logs-978-add-syntax-highlighting-to-regex-literals
Oct 2, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
dddb902
feat(search): Syntax highlight regex literals in the search bar
JoshuaKGoldberg fd69c98
ref(search): Give regex literals a base color distinct from metachara…
JoshuaKGoldberg 09bff06
ref(search): Trim the regex highlighting down
JoshuaKGoldberg 36fe41b
fix(search): Keep the regex overlay in step with the input's scroll
JoshuaKGoldberg b2d73f4
fix(search): Darken the regex character-set color for contrast
JoshuaKGoldberg 4c7e7c1
Webkit fixes
JoshuaKGoldberg 782a59d
fix(search): Replace regex overlay scroll sync with a shared grid cell
JoshuaKGoldberg e5c2a47
fix(search): Keep a mid-pattern caret in place while typing a long regex
JoshuaKGoldberg f640db0
fix(search): Color regex escapes with the content.success token
JoshuaKGoldberg ffa680b
fix(search): Soften the dark-mode green for regex escapes
JoshuaKGoldberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
static/app/components/searchQueryBuilder/tokens/filter/highlightedRegexPattern.spec.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import {render, screen} from 'sentry-test/reactTestingLibrary'; | ||
|
|
||
| import {loadPrismLanguage} from '@sentry/scraps/code'; | ||
|
|
||
| import {renderRegexPattern} from 'sentry/components/searchQueryBuilder/tokens/filter/highlightedRegexPattern'; | ||
|
|
||
| jest.unmock('prismjs'); | ||
|
|
||
| describe('renderRegexPattern', () => { | ||
| beforeAll(async () => { | ||
| await loadPrismLanguage('regex', {}); | ||
| }); | ||
|
|
||
| it('marks up anchors, character sets, and quantifiers when given a pattern', () => { | ||
| render(renderRegexPattern('^GET /api/\\d+$')); | ||
|
|
||
| expect(screen.getByText('^')).toHaveClass('anchor'); | ||
| expect(screen.getByText('GET /api/')).toBeInTheDocument(); | ||
| expect(screen.getByText('\\d')).toHaveClass('char-set'); | ||
| expect(screen.getByText('+')).toHaveClass('quantifier'); | ||
| expect(screen.getByText('$')).toHaveClass('anchor'); | ||
| }); | ||
|
|
||
| it('marks up the brackets and range when given a character class', () => { | ||
| render(renderRegexPattern('[a-z]{2,3}')); | ||
|
|
||
| expect(screen.getByText('[')).toHaveClass('char-class-punctuation'); | ||
| expect(screen.getByText('-')).toHaveClass('range-punctuation'); | ||
| expect(screen.getByText(']')).toHaveClass('char-class-punctuation'); | ||
| expect(screen.getByText('{2,3}')).toHaveClass('quantifier'); | ||
| }); | ||
|
|
||
| it('marks up the group and keeps the text when given a half-typed pattern', () => { | ||
| render(renderRegexPattern('(foo')); | ||
|
|
||
| expect(screen.getByText('(')).toHaveClass('group'); | ||
| expect(screen.getByText('foo')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('keeps the ellipsis when given a middle-truncated pattern', () => { | ||
| render(renderRegexPattern('^abc…xyz$')); | ||
|
|
||
| expect(screen.getByText('abc…xyz')).toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('renders the text when given a pattern of only literals', () => { | ||
| render(renderRegexPattern('firefox')); | ||
|
|
||
| expect(screen.getByText('firefox')).toBeInTheDocument(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.