Constructor
new Controller(target, config)
#
EditCheck controller
Manages triggering and updating edit checks.
Lifecycle:
- init.js makes one controller for each article target. The controller connects to each new surface on surfaceReady, which includes a section switch. When the surface is destroyed, it closes its sidebar and clears its state.
- A first refresh runs soon after the controller connects to a surface. Actions found in this refresh are not "new", because they are restored or are suggestions that the user did not cause. A refresh runs the checks of the mid-edit listeners at the same time.
- Mid-edit, an undo stack change runs the onDocumentChange checks. A selection in a different branch node runs the onBranchNodeChange checks, if the document changed after their last run. updateForListener keeps an existing action when it finds an equal one, so that the action keeps its state. The exception is a check that is equal to a suggestion: the check replaces the suggestion. updateForListener emits actionsUpdatedProgress for each action when it arrives. Until all checks for the listener are finished, a new action is pending. When they are finished, updateForListener emits actionsUpdated if the list of actions changed, or if an action was replaced. If a newer run for the same listener started before this, updateForListener ignores the results of the older run and does not emit actionsUpdated for it.
- Before save, the onBeforeSave checks run and inBeforeSave is true. getActions then gives only the pre-save actions.
Dialogs:
- Mid-edit, the controller opens one sidebar with showSidebar, when the first action that it can show arrives: sidebarEditCheckDialog on desktop, or gutterSidebarEditCheckDialog on mobile. On mobile, a gutter icon opens mobileEditCheckDialog, with a scope that limits it to the actions of that part of the page. A click on a different icon while it is open replaces its scope.
- Before save, the controller opens fixedEditCheckDialog if there are pre-save actions.
- A dialog reads its actions from getDisplayActions, in its setup and on each actionsUpdated, and keeps only the actions in its scope. getDisplayActions includes the pending actions. The window manager runs the setup some time after the open request, and a dialog gets no events before its setup. The read in setup includes the updates that occur while the dialog opens. A showSidebar call while the sidebar opens adds its new actions to the data that the setup reads. ensureActionIsShown waits until the sidebar is open before it focuses an action.
- Each dialog ignores action updates from the mode that it is not in: pre-save or mid-edit.
Parameters:
| Name | Type | Description | ||||||
|---|---|---|---|---|---|---|---|---|
target |
ve.init.mw.Target | The VisualEditor target |
||||||
config |
Object |
Properties:
|
- Mixes in:
- Source:
Methods
armAttentionHints()
#
Allow the attention effects to start appearing
- Source:
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:
clearEphemeralTagsForSelection()
#
Clear any ephemeral tags whose range the selection has left, and refresh if so
- Source:
clearState()
#
Reset controller state (on init or teardown)
- Source:
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:
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:
consumeDiscoverabilityHintsEnabled() → {boolean}
#
Check if the discoverability hints have already fired this page load, and if not, record that they have so later edit sessions in the same page load don't show them again
Not persisted server-side: the hints can only ever be armed via the way a user acts on the welcome dialog.
Returns:
If this is the first time this page load the hints have fired
- Type
- boolean
- Source:
Check if the discoverability hints have already fired this page load, and if not, record that they have so later edit sessions in the same page load don't show them again
Not persisted server-side: the hints can only ever be armed via the way a user acts on the welcome dialog.
consumePublishPath() → {boolean}
#
Check if the publish path card can show, and if so, do not show it again
Returns:
The publish path card can show
- Type
- boolean
- Source:
disableDiscoverability()
#
Permanently disable discoverability for this session and canceling any pending attention effect
- Source:
drawSelections()
#
Redraw selection highlights
- Source:
dropStaleSystemMessages()
#
Remove any system messages whose fragments changed, e.g. by an undo
- Source:
editChecksArePossible() → {boolean}
#
Check if any edit checks could be run for the current user/context
Returns:
- Type
- boolean
- Source:
ensureActionIsShown(action, [scrollConfig]) → {jQuery.Promise}
#
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 |
Returns:
Promise resolved with true once the action has been shown, or false if it could not be (e.g. the surface was destroyed while waiting)
- Type
- jQuery.Promise
- 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.
ensureAdjacentActionIsShown(action) → {jQuery.Promise}
#
Show the action adjacent to a given action in the display list
Shows the next action, or the previous if no action follows the given one
Parameters:
| Name | Type | Description |
|---|---|---|
action |
mw.editcheck.EditCheckAction | Action to find the neighbor of |
Returns:
Promise resolved with true once a neighboring action has been found and shown, or false if none was found or it could not be shown
- Type
- jQuery.Promise
- Source:
Show the action adjacent to a given action in the display list
Shows the next action, or the previous if no action follows the given one
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
- Source:
focusAction(action, [scrollTo], [scrollConfig]) → {jQuery.Promise}
#
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 |
Returns:
Promise resolved when scrolling is complete
- Type
- jQuery.Promise
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
Fires:
- Source:
forgetSystemMessage(action) → {boolean}private
#
Stop the timeout and the focus handler of a system message, and forget its state
Parameters:
| Name | Type | Description |
|---|---|---|
action |
mw.editcheck.EditCheckAction | Action of the system message |
Returns:
The system message was registered
- Type
- boolean
- Source:
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
- 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
getActionsWithPending() → {Array.<mw.editcheck.EditCheckAction>}
#
Get the current actions, and the mid-edit actions that are pending
A pending action arrived before all checks for its listener finished. As when the checks finish, a check replaces an equal suggestion, and other equal actions are shown once.
Returns:
Actions
- Source:
Get the current actions, and the mid-edit actions that are pending
A pending action arrived before all checks for its listener finished.
getCheckState() → {Object}
#
Get the session state to make checks with
Returns:
See the state parameter of mw.editcheck.BaseEditCheck
- Type
- Object
- Source:
getDisplayActions() → {Array.<mw.editcheck.EditCheckAction>}
#
Get the actions that a dialog can show
Returns:
Actions
- Source:
getSuggestionPlacement(actions) → {Object}
#
Find where suggestions are, compared to the section that is being edited
Parameters:
| Name | Type | Description |
|---|---|---|
actions |
Array.<mw.editcheck.EditCheckAction> |
Returns:
Number of suggestions in the section, and if there are suggestions above or below it
- Type
- Object
- Source:
getTarget() → {ve.init.mw.Target}
#
hideHelpPanelCtaIfNeeded()
#
Hide GrowthExperiments' help panel CTA button, if suggestions are visible
The button otherwise floats on top of/alongside our own suggestion-mode UI. There is no corresponding "show" hook, so once hidden this stays hidden for the rest of the session, even if suggestion mode is toggled off again (T431320).
- Source:
Hide GrowthExperiments' help panel CTA button, if suggestions are visible
The button otherwise floats on top of/alongside our own suggestion-mode UI.
isDiscoverabilityEnabled() → {boolean}
#
Check whether the suggestion discoverability features are enabled for this session
This considers the config/user preference, suggestion mode being enabled, and then any opt out.
Returns:
- Type
- boolean
- Source:
Check whether the suggestion discoverability features are enabled for this session
This considers the config/user preference, suggestion mode being enabled, and then any opt out.
markSuggestionDiscovered()
#
Record that the user has opened a suggestion
Used to turn off both attention effects
- Source:
Record that the user has opened a suggestion
Used to turn off both attention effects
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:
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:
onActionStreamed(listener)
#
Handle an action that arrives before all checks for its listener finish
Show it now, so that the user does not wait for the slowest check.
Parameters:
| Name | Type | Description |
|---|---|---|
listener |
string |
- Source:
Handle an action that arrives before all checks for its listener finish
Show it now, so that the user does not wait for the slowest check.
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:
onBranchNodeChange()
#
Handle changes to the selection moving between branch nodes
- Source:
onContextChange()
#
Handle contextChange events from the surface model
- Source:
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:
onSelect(selection)
#
Handle select events from the surface model
Parameters:
| Name | Type | Description |
|---|---|---|
selection |
ve.dm.Selection | New selection |
- Source:
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:
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:
registerActivity()
#
Register that the user edited, scrolled, or opened a suggestion Used for the suggestion discoverability attention effect
Cancels the current attention effect (if any) and restarts the idle countdown
- Source:
Register that the user edited, scrolled, or opened a suggestion Used for the suggestion discoverability attention effect
Cancels the current attention effect (if any) and restarts the idle countdown
registerSystemMessage(fragment, config) → {Promise}
#
Register a system message tied to a fragment
Shown as an EditCheckAction card at a resolved action's location.
The action is added at once, so that a dialog whose last action completed has the message to show, and does not close.
Parameters:
| Name | Type | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
fragment |
ve.dm.SurfaceFragment | Fragment where the resolved action was |
|||||||||||||||
config |
Object | EditCheckAction configuration Properties:
|
Returns:
Resolves when the action is announced as new
- Type
- Promise
Fires:
- Source:
Register a system message tied to a fragment
Shown as an EditCheckAction card at a resolved action's location.
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:
removeSystemMessage(action)
#
Remove a system message and its action
Parameters:
| Name | Type | Description |
|---|---|---|
action |
mw.editcheck.EditCheckAction | Action of the system message |
- Source:
restoreToolbar(target)
#
Restores the original toolbar tools after review mode is complete.
Parameters:
| Name | Type | Description |
|---|---|---|
target |
ve.init.mw.ArticleTarget |
- Source:
scheduleAttentionIdleTimer()
#
(Re)start the idle countdown that brings the attention effect back after a delay
Does nothing if discoverability isn't active, no suggestion exists anywhere on the page, a suggestion has already been opened, or the hints haven't been armed yet
- Source:
(Re)start the idle countdown that brings the attention effect back after a delay
Does nothing if discoverability isn't active, no suggestion exists anywhere on the page, a suggestion has already been opened, or the hints haven't been armed yet
scrollActionIntoView(action, [scrollConfig]) → {jQuery.Promise}
#
Scrolls an action's selection into view
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
action |
mw.editcheck.EditCheckAction | ||
scrollConfig |
Object |
optional |
Configuration for scrolling |
Returns:
Promise resolved when scrolling is complete
- Type
- jQuery.Promise
- Source:
setAttentionActive(value)
#
Set whether the "View suggestions" button's attention effect is active
Parameters:
| Name | Type | Description |
|---|---|---|
value |
boolean |
Fires:
- Source:
setIconAttentionActive(value)
#
Set whether a suggestion icon's attention effect is active
Parameters:
| Name | Type | Description |
|---|---|---|
value |
boolean |
Fires:
- Source:
setIgnoreNextSelectionChange([ignore])
#
Whether to ignore the next select event that is received
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
ignore |
boolean |
optional |
true |
- Source:
setIgnoreVirtualKeyboardChange([ignore])
#
Whether to ignore virtualKeyboardChange events
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
ignore |
boolean |
optional |
true |
- Source:
setScrollIntoViewSuppressed(value)
#
Set whether the "View suggestions" button should be hidden entirely
Parameters:
| Name | Type | Description |
|---|---|---|
value |
boolean |
Fires:
- Source:
setup()
#
Set up controller
- Source:
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:
setupToolbar(target)
#
Replace toolbar tools for review mode during pre-save checks.
Parameters:
| Name | Type | Description |
|---|---|---|
target |
ve.init.mw.ArticleTarget |
- Source:
showSidebar(newActions) → {jQuery.Promise}
#
Open the mid-edit sidebar, if it is not open
The sidebar reads the actions from the controller in its setup.
Parameters:
| Name | Type | Description |
|---|---|---|
newActions |
Array.<mw.editcheck.EditCheckAction> | Newly added actions, which the sidebar can focus |
Returns:
Promise which resolves when the sidebar is open
- Type
- jQuery.Promise
- Source:
Open the mid-edit sidebar, if it is not open
The sidebar reads the actions from the controller in its setup.
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:
trackAction(action)
#
Record when an action is shown, seen or used
Parameters:
| Name | Type | Description |
|---|---|---|
action |
mw.editcheck.EditCheckAction |
- Source:
trackRule(action, event)
#
Count one lifecycle event against the community-defined rule that caused it
The rule ID has no fixed set of values, so a cross with the check labels makes too many series.
Parameters:
| Name | Type | Description |
|---|---|---|
action |
mw.editcheck.EditCheckAction | |
event |
string | Lifecycle event: 'shown', 'seen', or the choice taken |
- Source:
Count one lifecycle event against the community-defined rule that caused it
The rule ID has no fixed set of values, so a cross with the check labels makes too many series.
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:
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:
updatePositions()
#
Update position of edit check highlights
Fires:
- Source:
updateSuggestionCount(count)
#
Update the suggestion count shown on the toolbar tool
Parameters:
| Name | Type | Description |
|---|---|---|
count |
number | The number of suggestions |
- Source:
updateSuggestionIndicators(actions)
#
Update the suggestion count and the edit-full-page indicators
Parameters:
| Name | Type | Description |
|---|---|---|
actions |
Array.<mw.editcheck.EditCheckAction> | All current mid-edit actions |
- Source: