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:
- Map.<string>
- 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:
disabledPreferences :Set.<string>
#
Preferences that are disabled from being changed in the panel or dialog
when lockPreference() is called.
Type:
- Set.<string>
- Source:
Preferences that are disabled from being changed in the panel or dialog
when lockPreference() is called.
extension
#
- Source:
extensionRegistry :CodeMirrorExtensionRegistry
#
isVisualEditor :boolean
#
mode :string
#
optionName :string
#
panel
#
- Source:
panelStateField :StateField
#
prefsToggleEffect :StateEffectType
#
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:
- Array.<string>
- 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()
#
- Source:
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
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
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:
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
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
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.