codemirror: Fix initial pattern type not being recognized
Created by: fkling
Fixes #34824 (closed)
The root issue was that the extensions get recreated due to changes
higher up in the component tree. However, because the pattern type is
set via a transaction the current value was lost and the extension
default back to literal
.
Order of events:
- Editor gets initialized
- Pattern type defaults to
literal
- Pattern type defaults to
- Transaction gets triggered (via hook) to set pattern type to
regex
- Editor gets initialized`
- Pattern type defaults to
literal
- Pattern type defaults to
The hook that sets the pattern type via a transaction is not triggered again because its depdencies (editor instance, pattern type) didn't change.
The fix is to pass the current pattern type when initializing the extension.
I also looked over the code to see if there are other extension that would exhibit the same problem, but this one seems to be the only one.
https://user-images.githubusercontent.com/179026/166674916-765f19cf-35a1-4eb5-ab8b-0022feaf025c.mp4
Test plan
Opening the link in the issue correctly highlights the query and shows the correct hover information.
App preview:
Check out the client app preview documentation to learn more.