Extends
Constructor
new CodeMirrorVisualEditor(surface, langSupport)
#
Properties
$textarea :jQuery
#
jQuery instance of the textarea for use with WikiEditor and jQuery plugins.
Type:
- Overrides:
- Source:
activeLineExtension :Extension
#
Extension for highlighting the active line.
Type:
- Overrides:
- Source:
bracketMatchingExtension :Extension
#
This extension adds bracket matching to the CodeMirror editor.
Type:
- Overrides:
- Source:
child :CodeMirrorChild
#
Get a CodeMirrorChild object for use on other textareas that
should have preferences synced with this CodeMirror instance.
Type:
- Overrides:
- Source:
Get a CodeMirrorChild object for use on other textareas that
should have preferences synced with this CodeMirror instance.
closeBracketsExtension :Extension
#
This extension adds automatic closing of brackets to the CodeMirror editor.
Type:
- Overrides:
- Source:
container :HTMLDivElement
#
The .ext-codemirror-wrapper container. This houses both the original textarea and the CodeMirror editor.
Type:
- Overrides:
- Source:
contentAttributesExtension :Extensionprotected
#
This specifies which attributes get added to the CodeMirror contenteditable .cm-content.
Subclasses are safe to override this method, but attributes here are considered vital.
Type:
.cm-content.
defaultExtensions :Extension|Array.<Extension>
#
Default extensions used by CodeMirror.
Extensions here should be applicable to all theoretical uses of CodeMirror in MediaWiki.
This getter can be overridden to apply additional extensions before
initialization. To apply a new extension after initialization,
use applyExtension(), or through
CodeMirrorExtensionRegistry using
register() if it needs
to be reconfigured (such as toggling on and off).
Type:
- Overrides:
- Source:
- See:
dirCompartment :Compartment
#
Compartment to control the direction of the editor.
Type:
- Overrides:
- Source:
dirExtension :Extensionprotected
#
This extension adds the ability to change the direction of the editor.
Type:
- Overrides:
- Source:
domEventHandlersExtension :Extensionprotected
#
Extension to bubble some DOM events to the original textarea.
The CodeMirror events are natively fired on the EditorView's
.cm-content element, which is accessible through
. The view.contentDOMscroll event is fired on
the .cm-scroller element, which is accessible through
.view.scrollDOM
Type:
- Overrides:
- Source:
editorAttributesExtension :Extensionprotected
#
This specifies which attributes get added to the .cm-editor element (the entire editor).
Subclasses are safe to override this method, but attributes here are considered vital.
Type:
.cm-editor element (the entire editor).
extensionRegistry :CodeMirrorExtensionRegistry
#
Extensions.
gotoLine :CodeMirrorGotoLine
#
The go-to line panel.
Type:
- Overrides:
- Source:
heightExtension :Extension
#
This extension sets the height of the CodeMirror editor to match the
textarea. This getter can be overridden to
change the height of the editor, but it's usually simpler to set the
height of the textarea using CSS prior to initialization.
Type:
- Overrides:
- Source:
This extension sets the height of the CodeMirror editor to match the
textarea.
isActive :boolean
#
Whether the CodeMirror instance is active.
Type:
- boolean
- Overrides:
- Source:
keymap :CodeMirrorKeymap
#
CodeMirror key mappings and help dialog.
Type:
- Overrides:
- Source:
langExtension :LanguageSupport
#
Language support and its extension(s).
Type:
- Overrides:
- Source:
lintExtension :Extensionprotected
#
This extension adds the ability to lint the code in the editor.
Type:
- Overrides:
- Source:
lintSource :LintSource|undefined
#
undefined
#
mode :string
#
The CodeMirror "mode" (language).
Type:
- string
- Overrides:
- Source:
phrasesExtension :Extensionprotected
#
Overrides for the CodeMirror library's internalization system.
Type:
- Overrides:
- Source:
- See:
preferences :CodeMirrorPreferences
#
The CodeMirror preferences panel.
Type:
- Overrides:
- Source:
readOnly :boolean
#
Whether the textarea is read-only.
Type:
- boolean
- Overrides:
- Source:
search :CodeMirrorSearch
#
The CodeMirror search panel.
Type:
- Overrides:
- Source:
searchExtension :Extension
#
Extension for search and goto line functionality.
Type:
- Overrides:
- Source:
specialCharsExtension :Extensionprotected
#
We give a small subset of special characters a tooltip explaining what they are. The messages and for what characters are defined here. Any character that does not have a message will instead use CM6 defaults, which is the localization of 'codemirror-control-character' followed by the Unicode number.
Type:
- Overrides:
- Source:
- See:
surface :ve.ui.Surface|null
#
null
#
surfaceView :ve.ce.Surface
#
textSelection :CodeMirrorTextSelection
#
jQuery.textSelection overrides for CodeMirror.
Type:
- Overrides:
- Source:
textarea :HTMLTextAreaElement
#
The textarea that CodeMirror is bound to.
Type:
- Overrides:
- Source:
updateExtension :Extension
#
This extension listens for changes in the CodeMirror editor and fires
the ext.CodeMirror.input hook with the ViewUpdate object.
Type:
- Overrides:
- Source:
Fires:
This extension listens for changes in the CodeMirror editor and fires
the ext.CodeMirror.input hook with the ViewUpdate object.
view :EditorView
#
The editor user interface.
Type:
- Overrides:
- Source:
whitespaceExtension
#
This extension highlights whitespace characters.
- Overrides:
- Source:
Methods
activate()protected
#
Activate CodeMirror on the textarea.
This sets the state property and shows the editor view,
hiding the original textarea.
initialize is expected to be called before this method.
- Overrides:
- Source:
textarea.
addDarkModeMutationObserver()
#
Use a MutationObserver to watch for CSS class changes to the element, and update the CodeMirror editor's theme accordingly. This is ony necessary for non-wikitext, where we don't use our own CSS classes during tokenization.
- Overrides:
- Source:
Use a MutationObserver to watch for CSS class changes to the element, and update the CodeMirror editor's theme accordingly.
addEditRecoveredHandler()protected
#
Set a new edit recovery handler.
- Overrides:
- Source:
addFormSubmitHandler()protected
#
Sync the CodeMirror editor with the original textarea on form submission.
- Overrides:
- Source:
addMwHook(hook, fn)protected
#
Add a handler for the given Hook.
This method is used to ensure no hook handlers are duplicated across lifecycle methods,
All handlers will be removed during deactivation.
Parameters:
| Name | Type | Description |
|---|---|---|
hook |
string | |
fn |
function |
- Overrides:
- Source:
Hook.
addTextAreaJQueryHook()protected
#
Define jQuery hook for .val() on the textarea.
- Overrides:
- Source:
- See:
applyExtension(extension)
#
Apply an Extension to the CodeMirror editor.
This is accomplished through
top-level reconfiguration
of the EditorView.
If the extension needs to be reconfigured (such as toggling on and off), use the
extensionRegistry instead.
Example
const require = await mw.loader.using( 'ext.CodeMirror.v6' );
mw.hook( 'ext.CodeMirror.ready' ).add( ( cm ) => {
const { EditorView, Prec } = require( 'ext.CodeMirror.v6.lib' );
// Disable spellchecking. Use Prec.high() to override the
// contentAttributesExtension which adds spellcheck="true".
cm.applyExtension( Prec.high( EditorView.contentAttributes.of( {
spellcheck: 'false'
} ) ) );
} );
Parameters:
| Name | Type | Description |
|---|---|---|
extension |
Extension |
- Overrides:
- Source:
- See:
Extension to the CodeMirror editor.
deactivate()protected
#
Deactivate CodeMirror on the textarea, restoring the original
textarea and hiding the editor.
destroy()
#
Destroy the CodeMirror instance and revert to the original textarea. This action should be considered irreversible.
- Overrides:
- Source:
Fires:
initialize([extensions])
#
Setup CodeMirror and add it to the DOM. This will hide the original textarea.
This method should only be called once per instance. Use toggle,
activate, and deactivate
to enable or disable the same CodeMirror instance programmatically, and restore or hide
the original textarea.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
extensions |
Extension | Array.<Extension> |
optional |
this.defaultExtensions
|
Extensions to use. |
- Overrides:
- Source:
Fires:
logEditFeature(action)protected
#
Log usage of CodeMirror.
Parameters:
| Name | Type | Description |
|---|---|---|
action |
string |
- Overrides:
- Source:
- See:
setupFeatureLogging()protected
#
Add hook handlers to log usage of CodeMirror features.
- Overrides:
- Source:
toggle([force])
#
Toggle CodeMirror on or off from the textarea.
This will call initialize if CodeMirror
is being enabled for the first time.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
force |
boolean |
optional |
|
- Overrides:
- Source: