This module provides a Vue component that wraps the CodeMirror class.
The ResourceLoader module for the requested language mode is loaded on demand,
so the only dependency you need to declare is this one.
The contents of the editor are bound with v-model.
Props:
modelValue{string} Contents of the editor.mode{string} Language mode, i.e.javascript,pythonormediawiki.modeConfig{Object} Configuration for the mode, read only when the editor is created. Only themediawikimode uses this.readOnly{boolean} Make the contents read-only, but still selectable.disabled{boolean} Make the contents read-only and not focusable.placeholder{string} Shown while the editor is empty.rows{number} Height of the editor, in rows. The smallest height when the editor grows.autoHeight{boolean} Grow with the contents instead of keeping one height.maxRows{number} Largest height in rows before the editor scrolls. Makes the editor grow, soautoHeightis not needed as well.autofocus{boolean} Focus the editor once it is ready.theme{string} Theme name, overriding the user's preference. Read only when the editor is created.
Any other attribute, such as id or aria-label, goes to the textarea.
class, style and data-testid stay on the root element.
Events:
update:modelValue{string}ready{CodeMirror} The instance, for use withapplyExtension()andapplyLinter().error{Error} The mode is unknown, or its module failed to load.focus,blur{FocusEvent}
Changing mode rebuilds the editor, which keeps the contents but loses the
undo history and focus.
Example
// Add 'ext.CodeMirror.VueComponent' to your module's dependencies.
const CodeMirrorEditor = require( 'ext.CodeMirror.VueComponent' );
// <code-mirror-editor v-model="code" mode="python"></code-mirror-editor>
- Source:
- See: