add onSelectionChange callback
This commit is contained in:
parent
7f0e98ea93
commit
55b2d7f68f
3 changed files with 14 additions and 4 deletions
4
packages/react/dist/index.cjs.js
vendored
4
packages/react/dist/index.cjs.js
vendored
File diff suppressed because one or more lines are too long
7
packages/react/dist/index.es.js
vendored
7
packages/react/dist/index.es.js
vendored
|
|
@ -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]
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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]}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue