Expand all

CodeMirrorPreferences

CodeMirrorPreferences is a panel that allows users to configure CodeMirror preferences. It is toggled by pressing Ctrl-Shift-, (or Command-Shift-, on macOS). Only the commonly used "primary" preferences with a visual effect are shown in the panel, in order to reduce in-editor clutter. An "advanced" link is provided to open a dialog with all available preferences. This can also be opened by pressing Alt-Shift-,.

Note that this code, like MediaWiki Core, refers to the user's preferences as "options". In this class, "preferences" refer to the user's preferences for CodeMirror, which are stored as a single user 'option' in the database.

Constructor

new CodeMirrorPreferences(extensionRegistry, mode, [isVisualEditor]) #

Parameters:

Name Type Attributes Default Description
extensionRegistry CodeMirrorExtensionRegistry
mode string

The CodeMirror mode being used, e.g. 'mediawiki', 'javascript', etc.

isVisualEditor boolean optional
false

Whether the VE 2017 editor is being used.

Source:

Fires:

Properties

callbackPreferences :Map.<string> #

Preferences registered with registerCallback(). These do not have an associated Extension and instead execute a callback function when the preference is changed.

Type:

Source:

Preferences registered with registerCallback().

dialogConfig :Object #

Configuration for the full preferences dialog.

Each key is a section name having an i18n message key of the form codemirror-prefs-section-<section>.

Values are arrays of preference names that belong to that section. Any preference not listed here will be shown in the "Other" section.

Type:

Source:
Configuration for the full preferences dialog.

disabledPreferences :Set.<string> #

Preferences that are disabled from being changed in the panel or dialog when lockPreference() is called.

Type:

Source:

Preferences that are disabled from being changed in the panel or dialog when lockPreference() is called.

extension #

isVisualEditor :boolean #

Type:

  • boolean
Source:

mode :string #

Type:

  • string
Source:

optionName :string #

Type:

  • string
Source:

panelStateField :StateField #

preferences :Object #

The user's CodeMirror preferences.

Type:

Source:
The user's CodeMirror preferences.

primaryPreferences :Array.<string> #

Preferences that are shown in the preferences panel, as defined by $wgCodeMirrorPrimaryPreferences. These "primary" preferences should:

  • Be commonly used,
  • Be easy to understand,
  • Have an immediate visual effect, and
  • Limited to a small subset to avoid consuming too much in-editor space.

Type:

Source:

Preferences that are shown in the preferences panel, as defined by $wgCodeMirrorPrimaryPreferences.

Methods

fetchPreferences() → {Object} #

Fetch the user's CodeMirror preferences from the user options API, or clientside storage for unnamed users.

Source:

Returns:

Type
Object

Fetch the user's CodeMirror preferences from the user options API, or clientside storage for unnamed users.

firePreferencesApplyHook(prefName, [value]) #

Parameters:

Name Type Attributes Description
prefName string
value boolean optional
Source:

Fires:

getCheckbox() #

getDefaultPreferences() → {Object} #

The default CodeMirror preferences, as defined by $wgCodeMirrorPreferences and taking into account the page namespace and the CodeMirror mode.

Source:

Returns:

Type
Object

The default CodeMirror preferences, as defined by $wgCodeMirrorPreferences and taking into account the page namespace and the CodeMirror mode.

getPreference(prefName) → {boolean} #

Get the value of the given CodeMirror preference.

Parameters:

Name Type Description
prefName string
Source:

Returns:

Type
boolean
Get the value of the given CodeMirror preference.

hasNonDefaultPreferences() → {boolean} #

Check if the user has any preferences that differ from the defaults. This is used to determine whether EventLogging should happen.

Source:

Returns:

Type
boolean
Check if the user has any preferences that differ from the defaults.

lockPreference(prefName, view, [force]) #

Lock a preference to the given value, disabling the option in the preferences panel and dialog. The user option in the database is not changed.

This is useful for integrations that need to disable incompatible extensions.

Parameters:

Name Type Attributes Default Description
prefName string
view EditorView
force boolean optional
false

Force the extension to be enabled or disabled.

Source:

Lock a preference to the given value, disabling the option in the preferences panel and dialog.

onKeydownPanel(event) #

Handle keydown events on the preferences panel.

Parameters:

Name Type Description
event KeyboardEvent
Source:
Handle keydown events on the preferences panel.

registerCallback(name, callback, view) #

Instead of an Extension, register a callback function that is executed when the preference value is changed. The callback is executed immediately if the preference is already set when registered.

Parameters:

Name Type Description
name string
callback function

Function that takes the new preference value.

view EditorView
Source:

Instead of an Extension, register a callback function that is executed when the preference value is changed.

registerExtension(name, extension, view) #

Register an Extension with CodeMirrorExtensionRegistry and enable it if the corresponding preference is set.

Parameters:

Name Type Description
name string
extension Extension
view EditorView
Source:

Register an Extension with CodeMirrorExtensionRegistry and enable it if the corresponding preference is set.

setPreference(key, value) #

Set the given CodeMirror preference and update the user option in the database, or clientside storage for unnamed users.

Parameters:

Name Type Description
key string
value boolean
Source:

Set the given CodeMirror preference and update the user option in the database, or clientside storage for unnamed users.

showPreferencesDialog(view) → {boolean} #

Show the dialog with all available preferences.

Parameters:

Name Type Description
view EditorView
Source:

Returns:

Type
boolean
Show the dialog with all available preferences.

toggle(view, [force]) → {boolean} #

Toggle display of the preferences panel.

Parameters:

Name Type Attributes Description
view EditorView
force boolean optional

Force the panel to open or close.

Source:

Returns:

Type
boolean
Toggle display of the preferences panel.

toggleExtension(name, view) #

Toggle an Extension on or off with CodeMirrorExtensionRegistry and update the preference.

Parameters:

Name Type Description
name string
view EditorView
Source:

Toggle an Extension on or off with CodeMirrorExtensionRegistry and update the preference.