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

File diff suppressed because one or more lines are too long

View file

@ -109,7 +109,7 @@ const highlightField = StateField.define({
}, },
provide: (f) => EditorView.decorations.from(f) provide: (f) => EditorView.decorations.from(f)
}); });
function CodeMirror({ value, onChange, onViewChanged, onCursor, options, editorDidMount }) { function CodeMirror({ value, onChange, onViewChanged, onSelectionChange, options, editorDidMount }) {
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(_CodeMirror, { return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(_CodeMirror, {
value, value,
onChange: (value2) => { onChange: (value2) => {
@ -118,6 +118,11 @@ function CodeMirror({ value, onChange, onViewChanged, onCursor, options, editorD
onCreateEditor: (view) => { onCreateEditor: (view) => {
onViewChanged(view); onViewChanged(view);
}, },
onUpdate: (viewUpdate) => {
if (viewUpdate.selectionSet && onSelectionChange) {
onSelectionChange(viewUpdate.state.selection);
}
},
extensions: [javascript(), strudelTheme, highlightField, flashField] extensions: [javascript(), strudelTheme, highlightField, flashField]
})); }));
} }

View file

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