File tree Expand file tree Collapse file tree
src/extensions/codemirror Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -28,6 +28,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
2828 - header-menu items are vertically centered now
2929- ` Typography `
3030 - adjust displaying fallback symbols in different browsers
31+ - ` <CodeMirror /> `
32+ - use the latest provided ` onChange ` function
3133
3234### Changed
3335
Original file line number Diff line number Diff line change @@ -231,6 +231,10 @@ export const CodeEditor = ({
231231 currentView . current = view
232232 const currentReadOnly = React . useRef ( readOnly )
233233 currentReadOnly . current = readOnly
234+ const currentOnChange = React . useRef ( onChange )
235+ currentOnChange . current = onChange
236+ const currentDisabled = React . useRef ( disabled )
237+ currentDisabled . current = disabled
234238 const [ showPreview , setShowPreview ] = React . useState < boolean > ( false ) ;
235239 // CodeMirror Compartments in order to allow for re-configuration after initialization
236240 const readOnlyCompartment = React . useRef < Compartment > ( compartment ( ) )
@@ -319,11 +323,11 @@ export const CodeEditor = ({
319323 disabledCompartment . current . of ( EditorView ?. editable . of ( ! disabled ) ) ,
320324 AdaptedEditorViewDomEventHandlers ( domEventHandlers ) as Extension ,
321325 EditorView ?. updateListener . of ( ( v : ViewUpdate ) => {
322- if ( disabled ) return ;
326+ if ( currentDisabled . current ) return ;
323327
324- if ( onChange && v . docChanged ) {
328+ if ( currentOnChange . current && v . docChanged ) {
325329 // Only fire if the text has actually been changed
326- onChange ( v . state . doc . toString ( ) ) ;
330+ currentOnChange . current ( v . state . doc . toString ( ) ) ;
327331 }
328332
329333 if ( onSelection )
You can’t perform that action at this time.
0 commit comments