ProposedChangesController
Binds together a set of proposed changes with related editor instances and (optionally) with the view component.
When an AISuggestionContainerView is attached, the controller will provide all necessary data to render and
update the view according to the proposed changes set. It will also fully integrate with the editor instance to handle all user
interaction coming from the view.
The controller also provides methods for handling the proposed document changes: applyChange,
applyAllChanges, rejectChange, previewChange, highlightChange.
One controller instance handles all changes from the proposed changes set, even when they are related to multiple editor instances.
Properties
collection: ProposedChangesCollectionreadonlymodule:ai/toolkit/proposedchangescontrollertype~ProposedChangesController#collectionThe set of proposed changes under review.
Methods
applyAllChanges( asSuggestions ) → voidmodule:ai/toolkit/proposedchangescontrollertype~ProposedChangesController#applyAllChangesApplies every change that can still be applied, one undo step per document.
Parameters
asSuggestions: boolean
Returns
void
applyChange( index, asSuggestions ) → voidmodule:ai/toolkit/proposedchangescontrollertype~ProposedChangesController#applyChangeApplies the change at
indexto the related document, directly or as track-changes suggestions.Parameters
index: numberasSuggestions: boolean
Returns
void
attachView( view ) → voidmodule:ai/toolkit/proposedchangescontrollertype~ProposedChangesController#attachViewBinds the given view with the controller, so the view shows the changes and its actions decide on them.
Parameters
view: AISuggestionContainerView
Returns
void
delegate( events ) → EmitterMixinDelegateChaininheritedmodule:ai/toolkit/proposedchangescontrollertype~ProposedChangesController#delegateDelegates selected events to another
Emitter. For instance:
Copy codeemitterA.delegate( 'eventX' ).to( emitterB ); emitterA.delegate( 'eventX', 'eventY' ).to( emitterC );then
eventXis delegated (fired by)emitterBandemitterCalong withdata:
Copy codeemitterA.fire( 'eventX', data );and
eventYis delegated (fired by)emitterCalong withdata:
Copy codeemitterA.fire( 'eventY', data );Parameters
events: Array<string>Event names that will be delegated to another emitter.
Returns
destroy() → voidmodule:ai/toolkit/proposedchangescontrollertype~ProposedChangesController#destroyStops tracking the documents and releases everything the controller holds.
Returns
void
detachView() → voidmodule:ai/toolkit/proposedchangescontrollertype~ProposedChangesController#detachViewUnbinds the attached view, leaving the changes as they are.
Returns
void
fire( eventOrInfo, args ) → GetEventInfo<TEvent>[ 'return' ]inheritedmodule:ai/toolkit/proposedchangescontrollertype~ProposedChangesController#fireFires an event, executing all callbacks registered for it.
The first parameter passed to callbacks is an
EventInfoobject, followed by the optionalargsprovided in thefire()method call.Type parameters
Parameters
eventOrInfo: GetNameOrEventInfo<TEvent>The name of the event or
EventInfoobject if event is delegated.args: TEvent[ 'args' ]Additional arguments to be passed to the callbacks.
Returns
GetEventInfo<TEvent>[ 'return' ]By default the method returns
undefined. However, the return value can be changed by listeners through modification of theevt.return's property (the event info is the first param of every callback).
hideHighlight() → voidmodule:ai/toolkit/proposedchangescontrollertype~ProposedChangesController#hideHighlighthighlightChange( index ) → voidmodule:ai/toolkit/proposedchangescontrollertype~ProposedChangesController#highlightChangeHighlights the content the change at
indexcovers.Parameters
index: number
Returns
void
listenTo( emitter, event, callback, options? ) → voidinheritedmodule:ai/toolkit/proposedchangescontrollertype~ProposedChangesController#listenTo:BASE_EMITTERRegisters a callback function to be executed when an event is fired in a specific (emitter) object.
Events can be grouped in namespaces using
:. When namespaced event is fired, it additionally fires all callbacks for that namespace.
Copy code// myEmitter.on( ... ) is a shorthand for myEmitter.listenTo( myEmitter, ... ). myEmitter.on( 'myGroup', genericCallback ); myEmitter.on( 'myGroup:myEvent', specificCallback ); // genericCallback is fired. myEmitter.fire( 'myGroup' ); // both genericCallback and specificCallback are fired. myEmitter.fire( 'myGroup:myEvent' ); // genericCallback is fired even though there are no callbacks for "foo". myEmitter.fire( 'myGroup:foo' );An event callback can stop the event and set the return value of the
firemethod.Type parameters
Parameters
emitter: EmitterThe object that fires the event.
event: TEvent[ 'name' ]The name of the event.
callback: GetCallback<TEvent>The function to be called on event.
options?: GetCallbackOptions<TEvent>Additional options.
Returns
void
off( event, callback ) → voidinheritedmodule:ai/toolkit/proposedchangescontrollertype~ProposedChangesController#offStops executing the callback on the given event. Shorthand for
this.stopListening( this, event, callback ).Parameters
event: stringThe name of the event.
callback: FunctionThe function to stop being called.
Returns
void
on( event, callback, options? ) → voidinheritedmodule:ai/toolkit/proposedchangescontrollertype~ProposedChangesController#onRegisters a callback function to be executed when an event is fired.
Shorthand for
this.listenTo( this, event, callback, options )(it makes the emitter listen on itself).Type parameters
Parameters
event: TEvent[ 'name' ]The name of the event.
callback: GetCallback<TEvent>The function to be called on event.
options?: GetCallbackOptions<TEvent>Additional options.
Returns
void
once( event, callback, options? ) → voidinheritedmodule:ai/toolkit/proposedchangescontrollertype~ProposedChangesController#onceRegisters a callback function to be executed on the next time the event is fired only. This is similar to calling
onfollowed byoffin the callback.Type parameters
Parameters
event: TEvent[ 'name' ]The name of the event.
callback: GetCallback<TEvent>The function to be called on event.
options?: GetCallbackOptions<TEvent>Additional options.
Returns
void
previewChange( index ) → voidmodule:ai/toolkit/proposedchangescontrollertype~ProposedChangesController#previewChangeOpens the preview of the change at
indexin the document.Parameters
index: number
Returns
void
rejectChange( index ) → voidmodule:ai/toolkit/proposedchangescontrollertype~ProposedChangesController#rejectChangeRejects the change at
index, leaving the document as it is.Parameters
index: number
Returns
void
scrollToChange( index ) → voidmodule:ai/toolkit/proposedchangescontrollertype~ProposedChangesController#scrollToChangeScrolls the content the change at
indexcovers into view.Parameters
index: number
Returns
void
setShowDiff( showDiff ) → voidmodule:ai/toolkit/proposedchangescontrollertype~ProposedChangesController#setShowDiffWhether the attached view shows each change as a diff, or as the proposed content alone.
Parameters
showDiff: boolean
Returns
void
stopDelegating( event?, emitter? ) → voidinheritedmodule:ai/toolkit/proposedchangescontrollertype~ProposedChangesController#stopDelegatingStops delegating events. It can be used at different levels:
- To stop delegating all events.
- To stop delegating a specific event to all emitters.
- To stop delegating a specific event to a specific emitter.
Parameters
event?: stringThe name of the event to stop delegating. If omitted, stops it all delegations.
emitter?: Emitter(requires
event) The object to stop delegating a particular event to. If omitted, stops delegation ofeventto all emitters.
Returns
void
stopListening( emitter?, event?, callback? ) → voidinheritedmodule:ai/toolkit/proposedchangescontrollertype~ProposedChangesController#stopListening:BASE_STOPStops listening for events. It can be used at different levels:
- To stop listening to a specific callback.
- To stop listening to a specific event.
- To stop listening to all events fired by a specific object.
- To stop listening to all events fired by all objects.
Parameters
emitter?: EmitterThe object to stop listening to. If omitted, stops it for all objects.
event?: string(Requires the
emitter) The name of the event to stop listening to. If omitted, stops it for all events fromemitter.callback?: Function(Requires the
event) The function to be removed from the call list for the givenevent.
Returns
void