Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
- `<CodeMirror />`
- use the latest provided `onChange` function

### Changed

Expand Down
19 changes: 11 additions & 8 deletions src/extensions/codemirror/CodeMirror.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,14 @@ export const CodeEditor = ({
}: CodeEditorProps) => {
const parent = useRef<any>(undefined);
const [view, setView] = React.useState<EditorView | undefined>();
const currentView = React.useRef<EditorView>();
currentView.current = view;
const currentReadOnly = React.useRef(readOnly);
currentReadOnly.current = readOnly;
//const currentDisabled = React.useRef(disabled);
const currentView = React.useRef<EditorView>()
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<boolean>(false);
// CodeMirror Compartments in order to allow for re-configuration after initialization
const readOnlyCompartment = React.useRef<Compartment>(compartment())
Expand Down Expand Up @@ -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)
Expand Down