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
Work on Codemirror 6 highlighting #102
Work on Codemirror 6 highlighting #102
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you!
@@ -118,6 +119,29 @@ function App() { | |||
return () => window.removeEventListener('keydown', handleKeyPress); | |||
}, [pattern, code, activateCode, cycle]); | |||
|
|||
useEffect(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good! we could also move this to a custom hook like useHighlights({pattern,view,started})
or similar, then we could reuse it in the mini repl
// console.log('filter', f,t,value, e.value.from, e.value.to); | ||
}, | ||
}); | ||
if (e.is(setHighlights)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that looks much simpler than what I fabricated :D didn't know you could just set the Decorations directly
e.value | ||
.flatMap((event) => event.context.locations || []) | ||
.map(({ start, end }) => { | ||
let from = tr.newDoc.line(start.line).from + start.column; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should make offsetToPosition
/ positionToOffset
obsolete :)
related #28 |
Here's an implementation of highlight marking that queries the pattern every frame. There are certainly some performance optimizations that could be done (plus some nuances of exactly how it should behave when the user starts/stops the pattern), but I think this is a good conceptual starting-point and an implementation that seems to perform pretty well.
Let me know if you've got any thoughts!