add onSelectionChange callback

This commit is contained in:
Felix Roos 2022-08-05 23:50:42 +02:00
parent 7f0e98ea93
commit 55b2d7f68f
3 changed files with 14 additions and 4 deletions

View file

@ -78,7 +78,7 @@ const highlightField = StateField.define({
provide: (f) => EditorView.decorations.from(f),
});
export default function CodeMirror({ value, onChange, onViewChanged, onCursor, options, editorDidMount }) {
export default function CodeMirror({ value, onChange, onViewChanged, onSelectionChange, options, editorDidMount }) {
return (
<>
<_CodeMirror
@ -89,6 +89,11 @@ export default function CodeMirror({ value, onChange, onViewChanged, onCursor, o
onCreateEditor={(view) => {
onViewChanged(view);
}}
onUpdate={(viewUpdate) => {
if (viewUpdate.selectionSet && onSelectionChange) {
onSelectionChange(viewUpdate.state.selection);
}
}}
extensions={[javascript(), strudelTheme, highlightField, flashField]}
/>
</>