Extends
Constructor
new CodeMirrorVisualEditorHighlight(surface, langSupport, [matchTag])
#
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
surface |
ve.ui.Surface | ||
langSupport |
CodeMirrorMediaWiki | MediaWiki mode instance, exposing |
|
matchTag |
function |
optional |
Headless tag matcher |
Properties
$activeLineNode :jQuery|null
#
null
#
Node currently carrying ACTIVE_LINE_CLASS. Held as the element rather than a
line number: an edit elsewhere shifts line numbers, and clearing by index would then
strip the class off whichever node had moved into that slot, stranding this one.
Type:
-
jQuery
|
null
ACTIVE_LINE_CLASS.
$textarea :jQuery.<(HTMLTextAreaElement|ve.ui.Surface)>
#
jQuery instance of the textarea or VE surface for use with jQuery plugins.
Type:
- Overrides:
- Source:
activeLineExtension :Extension
#
Extension for highlighting the active line.
Type:
- Overrides:
- Source:
bracketConfig :Object
#
Bracket-matching config (bracket set and scan distance), reused from the mode.
Type:
bracketFrameHandle :number|null
#
null
#
Pending requestAnimationFrame handle for coalescing bracket-match updates.
Type:
-
number
|
null
bracketGroups :Set.<string>
#
Bracket highlight groups currently drawn, kept apart from the syntax groups so a syntax refresh does not clear them.
Type:
- Set.<string>
Bracket highlight groups currently drawn, kept apart from the syntax groups so a syntax refresh does not clear them.
bracketMatchingConfig :Config|undefined
#
undefined
#
The extended configuration for bracket matching.
Setting this will update the
bracket matching extension
Example
// Highlight matching angle brackets in addition to the default.
mw.hook( 'ext.CodeMirror.ready' ).add( ( cm ) => {
const config = cm.bracketMatchingConfig || {};
config.brackets = ( config.brackets || '()[]{}' ) + '<>';
cm.bracketMatchingConfig = config;
} );
Type:
-
Config
|
undefined
- 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:
columnGuideExtension :Extensionprotected
#
This extension adds a vertical column guide to the editor at column 80.
Type:
- Overrides:
- Source:
compactPanelsExtension :Extension
#
Extension for the compact panel design. The class it adds makes the search and go-to line panels float over the editor instead of pushing the contents down.
Type:
- Overrides:
- Source:
container :HTMLDivElement
#
The .ext-codemirror-wrapper container. This houses both the original textarea and the CodeMirror editor.
Type:
- Overrides:
- Source:
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:
drawnGroups :Set.<string>
#
editRecoveryExtension
#
Edit Recovery support.
- 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.
frameHandle :number|null
#
null
#
Pending requestAnimationFrame handle, used to coalesce refreshes.
Type:
-
number
|
null
gotoLine :CodeMirrorGotoLine
#
The go-to line panel.
Type:
- Overrides:
- Source:
headingFrameHandle :number|null
#
null
#
Pending requestAnimationFrame handle for heading updates.
Type:
-
number
|
null
headingLines :Map.<number, number>
#
Heading line numbers (1-based) to level, so the classes can be removed again.
Type:
- Map.<number, number>
highlightRefsExtension :Extensionprotected
#
The highlightRefs preference, which the mediawiki mode registers as a CodeMirror theme
where there is a view to apply one to.
Type:
The highlightRefs preference, which the mediawiki mode registers as a CodeMirror theme
where there is a view to apply one to.
highlightStyle :HighlightStyle
#
indentGuidesExtension :Extension
#
This extension adds indent guides to the CodeMirror editor.
Type:
- Overrides:
- Source:
isActive :boolean
#
Whether the CodeMirror instance is active.
Type:
- boolean
- Overrides:
- Source:
isDiscussionTools :boolean
#
Whether the surface belongs to DiscussionTools, which reuses the 2017 editor for replies and has no line numbers of its own.
Type:
- boolean
- Overrides:
- Source:
Whether the surface belongs to DiscussionTools, which reuses the 2017 editor for replies and has no line numbers of its own.
keymap :CodeMirrorKeymap
#
CodeMirror key mappings and help dialog.
Type:
- Overrides:
- Source:
langExtension :LanguageSupport
#
Language support and its extension(s).
Type:
- Overrides:
- Source:
lineNumberGutter :CodeMirrorVisualEditorHighlightLineNumbering
#
The line-number gutter. There is no EditorView to host CodeMirror's own, so this draws numbers beside VisualEditor's paragraphs instead.
Type:
lintApi :LintSource|undefined
#
undefined
#
The function to lint the code in the editor using a MediaWiki API.
It can be disabled by setting this.lintApi.disabled = true.
Example
mw.hook( 'ext.CodeMirror.ready' ).add( ( cm ) => {
if ( cm.lintApi ) {
cm.lintApi.disabled = true;
}
} );
Type:
-
LintSource
|
undefined
- Overrides:
- Source:
lintExtension :Extensionprotected
#
This extension adds the ability to lint the code in the editor.
Type:
- Overrides:
- Source:
lintSource :LintSource|undefined
#
undefined
#
The function to lint the code in the editor using a web worker.
It can be disabled by setting this.lintSource.disabled = true.
Example
mw.hook( 'ext.CodeMirror.ready' ).add( ( cm ) => {
if ( cm.lintSource ) {
cm.lintSource.disabled = true;
}
} );
Type:
-
LintSource
|
undefined
- Overrides:
- Source:
matchTag :function|null
#
null
#
Headless tag matcher, so tag pairs (e.g. <ref>/</ref>) match under the same
bracketMatching preference as brackets.
Type:
-
function
|
null
mode :string
#
The CodeMirror "mode" (language).
Type:
- string
- Overrides:
- Source:
openLinks :CodeMirrorVisualEditorOpenLinks|null
#
null
#
Modifier-click link opening, driven by VisualEditor's mouse events: the overlay is
pointer-events: none, so CodeMirror's own openLinks extension never fires here.
Type:
- Overrides:
- Source:
Modifier-click link opening, driven by VisualEditor's mouse events: the overlay is
pointer-events: none, so CodeMirror's own openLinks extension never fires here.
openLinksEnabled :boolean
#
Whether modifier-clicking a link opens it, from the user's openLinks preference.
Type:
- boolean
- Overrides:
- Source:
openLinks preference.
openLinksExtension :Extensionprotected
#
Holds the mark for the link under the pointer. Registered like any other preference, so
the registry turns it on and off with openLinks; the range itself moves by effect.
Type:
- Overrides:
- Source:
openWindows :number
#
Number of modal windows open over the surface. The highlights are suspended while
any is; see CodeMirrorVisualEditorHighlight#suspendWhileWindowOpen.
Type:
- number
parsePassTarget :number|null
#
null
#
The source offset that the pass count applies to. If the viewport moves to a different offset, the count starts again.
Type:
-
number
|
null
parsePasses :number
#
The number of sequential passes that ended with the parse short of the viewport.
See MAX_PARSE_PASSES.
Type:
- number
persistPreferences :booleanprotected
#
Whether to save preference changes to the user's options. Subclasses that are not the
user's main editor should override this and return false, so that the editor does not
change preferences the user set elsewhere. Preferences are still read, and still apply
for the life of the editor.
Note this is distinct from locked preferences,
which force a specific PrefValue for the life of the editor.
Type:
- boolean
- Overrides:
- Source:
phrasesExtension :Extensionprotected
#
Overrides for the CodeMirror library's internalization system.
Type:
- Overrides:
- Source:
- See:
preferences :CodeMirrorPreferences
#
The CodeMirror preferences dialog.
Type:
- Overrides:
- Source:
readOnly :boolean
#
Whether the editor is read-only. Assigning to this reconfigures the editor in place,
so it can be changed at any time after initialization.
Before then it comes from initialReadOnly.
A read-only editor is still focusable and its contents still selectable. Use
EditorView.editable to make it non-editable.
Type:
- boolean
- Overrides:
- Source:
readOnlyExtension :Extensionprotected
#
The read-only state of the editor, in a Compartment so that
readOnly can reconfigure it after initialization.
Type:
- Overrides:
- Source:
The read-only state of the editor, in a Compartment so that
readOnly can reconfigure it after initialization.
search :CodeMirrorSearch
#
The CodeMirror search panel.
Type:
- Overrides:
- Source:
searchExtension :Extension
#
Extension for search and goto line functionality.
Type:
- Overrides:
- Source:
sortLines :CodeMirrorSortLines
#
CodeMirror line sorting 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:
state :EditorState|undefined
#
undefined
#
The current EditorState of the CodeMirror editor.
This is given by the EditorView instance, which is only available
after initialization.
Type:
-
EditorState
|
undefined
- Overrides:
- Source:
EditorState of the CodeMirror editor.
supportedPreferences :Array.<string>
#
ve.ui.CodeMirrorPreferencesPage.
surface :ve.ui.Surface
#
The VisualEditor surface.
Type:
- Overrides:
- Source:
surfaceView :ve.ce.Surface
#
The ContentEditable surface.
Type:
- Overrides:
- Source:
suspendEnabled :boolean
#
Type:
- boolean
suspendWhileWindowOpen :boolean
#
Whether to suspend the highlights while a modal window is open.
In Safari the cost to paint the highlights increases with the number of registered ranges. The size of each range does not change it. A window repaints the whole viewport when it opens, so on a long page the tab stops responding for more than a minute. See WebKit 323171.
Set this to false, or load the page with cmsuspend=0, to keep the highlights
registered and show the browser bug again.
Type:
- boolean
suspended :boolean
#
Whether the highlights are currently suspended.
Type:
- boolean
syntaxHighlightingEnabled :boolean
#
Whether to paint syntax colors: the no-highlight theme (T419339) turns them off.
Bracket matching and line numbering have their own preferences and are unaffected,
matching CodeMirrorThemes, where those styles sit outside the theme's rules.
Type:
- boolean
no-highlight theme (T419339) turns them off.
textSelection :CodeMirrorTextSelection
#
jQuery.textSelection overrides for CodeMirror.
Type:
- Overrides:
- Source:
textarea :HTMLTextAreaElement|ve.ui.Surface
#
The textarea or VE surface that CodeMirror is bound to.
Type:
- Overrides:
- Source:
theme :string
#
The applied theme: default, colorblind or no-highlight for this mode. Light and
dark variants are resolved in CSS, so only the base name matters here.
CodeMirrorThemes puts it in the state, since its own Extensions are styles for a
CodeMirror that does not exist here.
Type:
- string
default, colorblind or no-highlight for this mode.
themes :CodeMirrorThemes
#
The CodeMirror themes manager.
Type:
- Overrides:
- Source:
tokenizer :EditorState|null
#
null
#
Headless tokenizer state, driving CodeMirror's incremental parse without rendering.
Type:
-
EditorState
|
null
trailingWhitespaceDrawn :boolean
#
Whether the trailing-whitespace group is currently drawn, so clearing it is a no-op when it never was.
Type:
- boolean
Whether the trailing-whitespace group is currently drawn, so clearing it is a no-op when it never was.
trailingWhitespaceExtension
#
This extension highlights trailing whitespace characters.
- Overrides:
- Source:
trailingWhitespaceFrameHandle :number|null
#
null
#
Pending requestAnimationFrame handle for trailing-whitespace updates.
Type:
-
number
|
null
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:
whitespaceDrawn :boolean
#
Whether the whitespace group is currently drawn.
Type:
- boolean
whitespaceExtension
#
This extension highlights whitespace characters.
- Overrides:
- Source:
Methods
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.
addToDOM(extensions)protected
#
Add the CodeMirror EditorView to the DOM, wrapping
wrappedElement in the
container element.
Parameters:
| Name | Type | Description |
|---|---|---|
extensions |
Extension |
- Overrides:
- Source:
Add the CodeMirror EditorView to the DOM, wrapping
wrappedElement in the
container element.
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' );
mw.hook( 'ext.CodeMirror.ready' ).add( ( cm ) => {
const { EditorView, Prec } = require( 'ext.CodeMirror.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.
applyLinter(lint, [config])
#
Apply an extra linter to the CodeMirror editor.
This linter respects the user preference for enabling or disabling linting.
Example
// Report Ukrainian letter 'і' among Latin letters as a warning.
const lint = {
pattern: /[a-zA-Z]і|і(?=[a-zA-Z])/g,
callback( match ) {
return {
from: match.index + match[ 0 ].indexOf( 'і' ),
to: match.index + match[ 0 ].indexOf( 'і' ) + 1,
severity: 'warning',
message: 'Ukrainian letter "і" found among Latin letters.',
actions: [ {
name: 'To Latin',
apply( view, from, to ) {
view.dispatch( {
changes: { from, to, insert: 'i' }
} );
}
} ]
};
}
};
mw.hook( 'ext.CodeMirror.ready' ).add( ( cm ) => {
cm.applyLinter( lint );
} );
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
lint |
function | Object | Function that takes a string and returns an array of
|
|
config |
Object |
optional |
Optional configuration. |
- Overrides:
- Source:
linter to the CodeMirror editor.
bindSurface()protected
#
Everything this integration does to VisualEditor's surface while it is active: the
overlay styling, and the listeners that keep CodeMirror in step with the surface. Undone
by unbindSurface().
- Overrides:
- Source:
Everything this integration does to VisualEditor's surface while it is active: the overlay styling, and the listeners that keep CodeMirror in step with the surface.
dispatch(spec)
#
Apply a transaction
to the editor. Together with state, this is what makes a
CodeMirror instance an Editor.
Parameters:
| Name | Type | Description |
|---|---|---|
spec |
Object |
- Overrides:
- Source:
Apply a transaction to the editor.
getLineNumberingExtension([firstLineNumber]) → {Extension}
#
Line numbering, starting at the given number.
Use this instead of CodeMirror#lineNumberingExtension when the code in the editor
is part of a larger file, and the first line is not line 1.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
firstLineNumber |
number |
optional |
1 | Number to show for the first line. |
Returns:
- Type
- Extension
- Overrides:
- Source:
getNewEditorState(extensions) → {EditorState}protected
#
Create a new EditorState with the given extensions and the contents
of the element that CodeMirror is bound to.
Parameters:
| Name | Type | Description |
|---|---|---|
extensions |
Extension |
Returns:
- Type
- EditorState
- Overrides:
- Source:
Create a new EditorState with the given extensions and the contents
of the element that CodeMirror is bound to.
hideEditor()protected
#
Hide the editor and give jQuery.textSelection back to the textarea, as
deactivate() does on the way out. Integrations that render
no editor of their own should override this.
- Overrides:
- Source:
Hide the editor and give jQuery.textSelection back to the textarea, as
deactivate() does on the way out.
onDocumentChanged()protected
#
Update whatever tracks the document contents, once
onDocumentPrecommit() has mirrored a
change into CodeMirror.
- Overrides:
- Source:
Update whatever tracks the document contents, once
onDocumentPrecommit() has mirrored a
change into CodeMirror.
onDocumentPrecommit(tx)protected
#
Handle precommit events from the document, mirroring the change into CodeMirror.
The document is still in its 'old' state before the transaction has been applied at this point, so the offsets are those of the pre-transaction document. They go in one transaction, which CodeMirror rebases internally, rather than one at a time in reverse.
Parameters:
| Name | Type | Description |
|---|---|---|
tx |
ve.dm.Transaction |
removeFromDOM()protected
#
Remove the CodeMirror EditorView from the DOM, unwrapping the element it was
attached to, as the inverse of addToDOM(). Integrations that
attach CodeMirror to something other than a textarea should override this.
- Overrides:
- Source:
Remove the CodeMirror EditorView from the DOM, unwrapping the element it was
attached to, as the inverse of addToDOM().
removeMwHooks([hook], [fn])protected
#
Remove handlers registered with #addMwHook for the given Hook,
or remove all handlers if no hook is specified.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
hook |
string |
optional |
|
fn |
function |
optional |
If specified, only this handler will be removed for the given hook. |
- Overrides:
- Source:
Remove handlers registered with #addMwHook for the given Hook,
or remove all handlers if no hook is specified.
setCodeMirrorPreference(prefValue)
#
Save CodeMirror enabled preference.
Parameters:
| Name | Type | Description |
|---|---|---|
prefValue |
boolean |
|
- Overrides:
- Source:
showEditor()protected
#
Reveal the editor and route jQuery.textSelection through it, as
activate() does on the way in. Integrations that render no
editor of their own should override this.
- Overrides:
- Source:
Reveal the editor and route jQuery.textSelection through it, as
activate() does on the way in.
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 |
|
Fires:
- Overrides:
- Source:
unbindSurface()protected
#
Undo bindSurface(), leaving VisualEditor's
surface as it was found.
- Overrides:
- Source:
Undo bindSurface(), leaving VisualEditor's
surface as it was found.