Expand all

Controller

EditCheckController

Constructor

new Controller(target, config) #

EditCheck controller

Manages triggering and updating edit checks.

Parameters:

Name Type Description
target ve.init.mw.Target

The VisualEditor target

config Object
Properties:
Name Type Description
suggestionsModeAvailable boolean

Suggestions mode is available

Mixes in:
Source:

Methods

canBeShown(checkName, [suggestion]) → {boolean} #

Check if a given edit check could be run for the current user/context

Parameters:

Name Type Attributes Default Description
checkName string

Check name

suggestion boolean optional
false

Whether we are checking for suggestion mode

Returns:

Type
boolean
Source:
Check if a given edit check could be run for the current user/context

clearState() #

Reset controller state (on init or teardown)

Source:
Reset controller state (on init or teardown)

closeDialog([action]) → {jQuery.Promise} #

Closes the edit check dialog

Parameters:

Name Type Attributes Description
action string optional

Name of action which triggered the close ('mobile-keyboard', 'context', 'preSaveProcess')

Returns:

Type
jQuery.Promise
Source:
Closes the edit check dialog

closeSidebars([action]) → {jQuery.Promise} #

Closes the sidebar edit check dialogs (mid-edit).

Parameters:

Name Type Attributes Description
action string optional

Name of action which triggered the close (currently only 'preSaveProcess')

Returns:

Type
jQuery.Promise
Source:
Closes the sidebar edit check dialogs (mid-edit).

drawSelections() #

Redraw selection highlights

Source:
Redraw selection highlights

editChecksArePossible() → {boolean} #

Check if any edit checks could be run for the current user/context

Returns:

Type
boolean
Source:
Check if any edit checks could be run for the current user/context

ensureActionIsShown(action, [scrollConfig]) #

Make sure an action is visible to the user

This will scroll the action into view and make sure its widget is expanded so the contents can be seen.

Parameters:

Name Type Attributes Description
action mw.editcheck.EditCheckAction

Action to focus

scrollConfig Object | boolean optional

Configuration for scrolling or (deprecated) a boolean to set alignToTop

Source:

Make sure an action is visible to the user

This will scroll the action into view and make sure its widget is expanded so the contents can be seen.

filterActionsForDisplay(actions) → {Array.<mw.editcheck.EditCheckAction>} #

Filter actions for display based on current settings

Parameters:

Name Type Description
actions Array.<mw.editcheck.EditCheckAction>

Actions to filter

Returns:

Filtered actions

Type
Array.<mw.editcheck.EditCheckAction>
Source:
Filter actions for display based on current settings

focusAction(action, [scrollTo], [scrollConfig]) #

Trigger a focus state for a given action

Will emit a focusAction event if the focused action changed or if scrolling was requested.

Parameters:

Name Type Attributes Description
action mw.editcheck.EditCheckAction

Action to focus

scrollTo boolean optional

Scroll action's selection into view

scrollConfig Object optional

Configuration for scrolling

Fires:

Source:

Trigger a focus state for a given action

Will emit a focusAction event if the focused action changed or if scrolling was requested.

focusActionForSelection() #

Update actions based on the current selection

getActions([listener]) → {Array.<mw.editcheck.EditCheckAction>} #

Get actions by listener

If no listener is specified, then get all actions relevant to the current moment, i.e.:

  • During beforeSave, get onBeforeSave listeners
  • Otherwise, get all mid-edit listeners

Parameters:

Name Type Attributes Description
listener string optional

The listener; if omitted, get all relevant actions

Returns:

Actions

Type
Array.<mw.editcheck.EditCheckAction>
Source:

Get actions by listener

If no listener is specified, then get all actions relevant to the current moment, i.e.:

  • During beforeSave, get onBeforeSave listeners
  • Otherwise, get all mid-edit listeners

getTarget() → {ve.init.mw.Target} #

Get the current VE target

Returns:

Type
ve.init.mw.Target
Source:
Get the current VE target

onActionAct(action, promise, actionTaken) #

Handle instrumentation and tracking when an action is used

Parameters:

Name Type Description
action mw.editcheck.EditCheckAction

that was used

promise Promise | jQuery.Promise

that will resolve when the action finishes

actionTaken string

name of the action taken

Source:
Handle instrumentation and tracking when an action is used

onActionSeenOrShown(action, seenOrShown) #

Handle instrumentation and tracking when an action is shown or marked as seen

Parameters:

Name Type Description
action mw.editcheck.EditCheckAction

Action that was seen or shown

seenOrShown string

Whether the action was 'seen' or 'shown'

Source:
Handle instrumentation and tracking when an action is shown or marked as seen

onActionsUpdated(listener, actions, newActions, discardedActions) #

Handler when 'actionsUpdated' fires.

Updates gutter and highlights when the action list has changed. Displays the edit check dialog if it is not already on screen.

Parameters:

Name Type Description
listener string

e.g. onBeforeSave, onDocumentChange, onBranchNodeChange

actions Array.<mw.editcheck.EditCheckAction>
newActions Array.<mw.editcheck.EditCheckAction>
discardedActions Array.<mw.editcheck.EditCheckAction>

Listens to Events:

Source:
Handler when 'actionsUpdated' fires.

onBranchNodeChange() #

Handle changes to the selection moving between branch nodes

Source:
Handle changes to the selection moving between branch nodes

onContextChange() #

Handle contextChange events from the surface model

Source:
Handle contextChange events from the surface model

onDocumentUpdate() #

Handle changes to the document model

This event is only used for updating highlights.

Source:

Handle changes to the document model

This event is only used for updating highlights.

onPosition(passive) #

Handle position events from the surface view

Parameters:

Name Type Description
passive boolean

Event is passive (don't scroll)

Source:
Handle position events from the surface view

onSelect(selection) #

Handle select events from the surface model

Parameters:

Name Type Description
selection ve.dm.Selection

New selection

Source:
Handle select events from the surface model

onSidebarDialogsOpeningOrClosing(win, openingOrClosing) #

Handle sidebar dialog open/close events

Transition skin/VE components around to make room for sidebar

Parameters:

Name Type Description
win OO.ui.Window

The window instance

openingOrClosing jQuery.Promise

Promise that resolves when closing finishes

Source:

Handle sidebar dialog open/close events

Transition skin/VE components around to make room for sidebar

onUndoStackChange() #

Handle changes to the model's undo stack

This less-frequent event is used for updating actions.

Source:

Handle changes to the model's undo stack

This less-frequent event is used for updating actions.

onVirtualKeyboardChange() #

Handle virtual keyboard change events from the target

Source:
Handle virtual keyboard change events from the target

refresh(useCache) → {Promise.<Array.<mw.editcheck.EditCheckAction>>} #

Update edit check list

Parameters:

Name Type Description
useCache boolean

Whether to piggyback onto an existing refresh if one is ongoing

Returns:

An updated set of actions. This promise will resolve after any actionsUpdated events are fired.

Type
Promise.<Array.<mw.editcheck.EditCheckAction>>

Fires:

Source:
Update edit check list

removeAction(listener, action, rejected) #

Remove an edit check action

Parameters:

Name Type Description
listener string

Listener which triggered the action

action mw.editcheck.EditCheckAction

Action to remove

rejected boolean

The action was rejected

Fires:

Source:
Remove an edit check action

restoreToolbar(target) #

Restores the original toolbar tools after review mode is complete.

Parameters:

Name Type Description
target ve.init.mw.ArticleTarget
Source:
Restores the original toolbar tools after review mode is complete.

scrollActionIntoView(action, [scrollConfig]) #

Scrolls an action's selection into view

Parameters:

Name Type Attributes Description
action mw.editcheck.EditCheckAction
scrollConfig Object optional

Configuration for scrolling

Source:
Scrolls an action's selection into view

setIgnoreNextSelectionChange([ignore]) #

Whether to ignore the next select event that is received

Parameters:

Name Type Attributes Default Description
ignore boolean optional
true
Source:
Whether to ignore the next select event that is received

setup() #

Set up controller

Source:
Set up controller

setupPreSaveProcess() #

Adds the pre-save edit check dialog before the normal page commit dialog. Handles closing the mid-edit dialog, as well as restoring it if the user exits the pre-save check dialog.

We execute all pre-save checks, which may be asynchronous, and wait for them to complete before opening the pre-save dialog.

TODO: Set a time-out so that we don't hang forever if an async check takes too long.

Source:
Adds the pre-save edit check dialog before the normal page commit dialog.

setupToolbar(target) #

Replace toolbar tools for review mode during pre-save checks.

Parameters:

Name Type Description
target ve.init.mw.ArticleTarget
Source:
Replace toolbar tools for review mode during pre-save checks.

suppressSuggestionDisplay(suppress) #

Suppress suggestions without affecting user preferences

Suggestions will still continue to be generated and cached, just not displayed. For use by external tools.

Parameters:

Name Type Description
suppress boolean

if true, does not display any suggestions

Source:

Suppress suggestions without affecting user preferences

Suggestions will still continue to be generated and cached, just not displayed.

toggleSuggestionsVisible() #

Toggle whether suggestions are shown to the user.

Source:
Toggle whether suggestions are shown to the user.

updateCurrentBranchNodeFromSelection(selection) → {boolean} #

Set the current branch node from a selection

Parameters:

Name Type Description
selection ve.dm.Selection

New selection

Returns:

whether the branch node changed

Type
boolean
Source:
Set the current branch node from a selection

updateForListener(listener, fromRefresh) → {Promise.<Array.<mw.editcheck.EditCheckAction>>} #

Fires all edit checks associated with a given listener.

Actions are created anew for every run, but we want continuity for certain state changes. We therefore match them up to existing actions by checking for equality, ie, the same constructor and same ID or fragments.

We return a promise so that UI actions such as opening the pre-save dialog do not occur until checks have completed.

Parameters:

Name Type Description
listener string

e.g. onBeforeSave, onDocumentChange, onBranchNodeChange

fromRefresh boolean

Update comes from a manual refresh, not a real event

Returns:

An updated set of actions.

Type
Promise.<Array.<mw.editcheck.EditCheckAction>>

Fires:

Source:
Fires all edit checks associated with a given listener.

updatePositions() #

Update position of edit check highlights

Fires:

Source:
Update position of edit check highlights

updateSuggestionCount(count) #

Update the suggestion count shown on the toolbar tool

Parameters:

Name Type Description
count number

The number of suggestions

Source:
Update the suggestion count shown on the toolbar tool

whenActionsSettled() → {Promise.<Array.<mw.editcheck.EditCheckAction>>} #

Wait for any current action generation to finish

Returns:

An updated set of actions. This promise will resolve after any actionsUpdated events are fired.

Type
Promise.<Array.<mw.editcheck.EditCheckAction>>
Source:
Wait for any current action generation to finish