diff --git a/CHANGELOG.md b/CHANGELOG.md
index ce3c53c7..0f0b3030 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -46,6 +46,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- use correct font sizes when `size` property is set
- `Typography`
- adjust displaying fallback symbols in different browsers
+- ``
+ - use the latest provided `onChange` function
### Changed
diff --git a/src/extensions/codemirror/CodeMirror.tsx b/src/extensions/codemirror/CodeMirror.tsx
index 8ef1a0bf..bcaec554 100644
--- a/src/extensions/codemirror/CodeMirror.tsx
+++ b/src/extensions/codemirror/CodeMirror.tsx
@@ -227,11 +227,14 @@ export const CodeEditor = ({
}: CodeEditorProps) => {
const parent = useRef(undefined);
const [view, setView] = React.useState();
- const currentView = React.useRef();
- currentView.current = view;
- const currentReadOnly = React.useRef(readOnly);
- currentReadOnly.current = readOnly;
- //const currentDisabled = React.useRef(disabled);
+ const currentView = React.useRef()
+ currentView.current = view
+ const currentReadOnly = React.useRef(readOnly)
+ currentReadOnly.current = readOnly
+ const currentOnChange = React.useRef(onChange)
+ currentOnChange.current = onChange
+ const currentDisabled = React.useRef(disabled)
+ currentDisabled.current = disabled
const [showPreview, setShowPreview] = React.useState(false);
// CodeMirror Compartments in order to allow for re-configuration after initialization
const readOnlyCompartment = React.useRef(compartment())
@@ -320,11 +323,11 @@ export const CodeEditor = ({
disabledCompartment.current.of(EditorView?.editable.of(!disabled)),
AdaptedEditorViewDomEventHandlers(domEventHandlers) as Extension,
EditorView?.updateListener.of((v: ViewUpdate) => {
- if (disabled) return;
+ if (currentDisabled.current) return;
- if (onChange && v.docChanged) {
+ if (currentOnChange.current && v.docChanged) {
// Only fire if the text has actually been changed
- onChange(v.state.doc.toString());
+ currentOnChange.current(v.state.doc.toString());
}
if (onSelection)