EditingView
Editor's view controller class. Its main responsibility is DOM - View management for editing purposes, to provide abstraction over the DOM structure and events and hide all browsers quirks.
View controller renders view document to DOM whenever view structure changes. To determine when view can be rendered, all changes need to be done using the change method, using ViewDowncastWriter:
view.change( writer => {
	writer.insert( position, writer.createText( 'foo' ) );
} );
View controller also register observers which observes changes on DOM and fire events on the Document. Note that the following observers are added by the class constructor and are always available:
SelectionObserver,FocusObserver,KeyObserver,FakeSelectionObserver.CompositionObserver.InputObserver.ArrowKeysObserver.TabObserver.
This class also binds the DOM and the view elements.
If you do not need full a DOM - view management, and only want to transform a tree of view elements to a tree of DOM elements you do not need this controller. You can use the ViewDomConverter instead.
Properties
document : ViewDocumentreadonlymodule:engine/view/view~EditingView#documentInstance of the
ViewDocumentassociated with this view controller.domConverter : ViewDomConverterreadonlymodule:engine/view/view~EditingView#domConverterInstance of the domConverter used by renderer and observers.
domRoots : Map<string, HTMLElement>readonlymodule:engine/view/view~EditingView#domRootsRoots of the DOM tree. Map on the
HTMLElements with roots names as keys.hasDomSelection : booleanreadonly observablemodule:engine/view/view~EditingView#hasDomSelectionInforms whether the DOM selection is inside any of the DOM roots managed by the view.
isRenderingInProgress : booleanreadonly observablemodule:engine/view/view~EditingView#isRenderingInProgressUsed to prevent calling
forceRenderandchangeduring rendering view to the DOM._hasChangedSinceTheLastRendering : booleanprivatemodule:engine/view/view~EditingView#_hasChangedSinceTheLastRenderingInternal flag that disables rendering when there are no changes since the last rendering. It stores information about changed selection and changed elements from attached document roots.
_initialDomRootAttributes : WeakMap<HTMLElement, Record<string, string>>privatereadonlymodule:engine/view/view~EditingView#_initialDomRootAttributesA DOM root attributes cache. It saves the initial values of DOM root attributes before the DOM element is attached to the view so later on, when the view is destroyed (
detachDomRoot), they can be easily restored. This way, the DOM element can go back to the (clean) state as if the editing view never used it._observers : Map<ObserverConstructor, Observer>privatereadonlymodule:engine/view/view~EditingView#_observersMap of registered observers.
_ongoingChange : booleanprivatemodule:engine/view/view~EditingView#_ongoingChangeIs set to
truewhen view changes are currently in progress._postFixersInProgress : booleanprivatemodule:engine/view/view~EditingView#_postFixersInProgressUsed to prevent calling
forceRenderandchangeduring rendering view to the DOM._renderer : ViewRendererprivatereadonlymodule:engine/view/view~EditingView#_rendererInstance of the renderer.
_renderingDisabled : booleanprivatemodule:engine/view/view~EditingView#_renderingDisabledInternal flag to temporary disable rendering. See the usage in the
_disableRendering._writer : ViewDowncastWriterprivatereadonlymodule:engine/view/view~EditingView#_writerViewDowncastWriter instance used in change method callbacks.
Methods
constructor( stylesProcessor )module:engine/view/view~EditingView#constructorParameters
stylesProcessor : StylesProcessorThe styles processor instance.
addObserver( ObserverConstructor ) → Observermodule:engine/view/view~EditingView#addObserverCreates observer of the given type if not yet created, enables it and attaches to all existing and future DOM roots.
Note: Observers are recognized by their constructor (classes). A single observer will be instantiated and used only when registered for the first time. This means that features and other components can register a single observer multiple times without caring whether it has been already added or not.
Parameters
ObserverConstructor : ObserverConstructorThe constructor of an observer to add. Should create an instance inheriting from
Observer.
Returns
ObserverAdded observer instance.
attachDomRoot( domRoot, name ) → voidmodule:engine/view/view~EditingView#attachDomRootAttaches a DOM root element to the view element and enable all observers on that element. Also mark element to be synchronized with the view what means that all child nodes will be removed and replaced with content of the view root.
This method also will change view element name as the same as tag name of given dom root. Name is always transformed to lower case.
Note: Use
detachDomRoot()to revert this action.Parameters
domRoot : HTMLElementDOM root element.
name : stringName of the root.
Defaults to
'main'
Returns
void
bind( bindProperties ) → ObservableMultiBindChaininheritedmodule:engine/view/view~EditingView#bind:MANY_BINDBinds observable properties to other objects implementing the
Observableinterface.Read more in the dedicated guide covering the topic of property bindings with some additional examples.
Consider two objects: a
buttonand an associatedcommand(bothObservable).A simple property binding could be as follows:
button.bind( 'isEnabled' ).to( command, 'isEnabled' );Copy codeor even shorter:
button.bind( 'isEnabled' ).to( command );Copy codewhich works in the following way:
button.isEnabledinstantly equalscommand.isEnabled,- whenever 
command.isEnabledchanges,button.isEnabledwill immediately reflect its value. 
Note: To release the binding, use
unbind.You can also "rename" the property in the binding by specifying the new name in the
to()chain:button.bind( 'isEnabled' ).to( command, 'isWorking' );Copy codeIt is possible to bind more than one property at a time to shorten the code:
button.bind( 'isEnabled', 'value' ).to( command );Copy codewhich corresponds to:
button.bind( 'isEnabled' ).to( command ); button.bind( 'value' ).to( command );Copy codeThe binding can include more than one observable, combining multiple data sources in a custom callback:
button.bind( 'isEnabled' ).to( command, 'isEnabled', ui, 'isVisible', ( isCommandEnabled, isUIVisible ) => isCommandEnabled && isUIVisible );Copy codeUsing a custom callback allows processing the value before passing it to the target property:
button.bind( 'isEnabled' ).to( command, 'value', value => value === 'heading1' );Copy codeIt is also possible to bind to the same property in an array of observables. To bind a
buttonto multiple commands (alsoObservables) so that each and every one of them must be enabled for the button to become enabled, use the following code:button.bind( 'isEnabled' ).toMany( [ commandA, commandB, commandC ], 'isEnabled', ( isAEnabled, isBEnabled, isCEnabled ) => isAEnabled && isBEnabled && isCEnabled );Copy codeParameters
bindProperties : Array<'off' | 'set' | 'bind' | 'unbind' | 'decorate' | 'stopListening' | 'on' | 'once' | 'listenTo' | 'fire' | 'delegate' | 'stopDelegating' | 'change' | 'focus' | 'document' | 'destroy' | 'createPositionAt' | 'createPositionAfter' | 'createPositionBefore' | 'createRange' | 'createRangeIn' | 'createRangeOn' | 'createSelection' | 'domConverter' | 'domRoots' | 'isRenderingInProgress' | 'hasDomSelection' | 'attachDomRoot' | 'detachDomRoot' | 'getDomRoot' | 'addObserver' | 'getObserver' | 'disableObservers' | 'enableObservers' | 'scrollToTheSelection' | 'forceRender' | '_disableRendering'>Observable properties that will be bound to other observable(s).
Returns
ObservableMultiBindChainThe bind chain with the
to()andtoMany()methods.
bind( bindProperty1, bindProperty2 ) → ObservableDualBindChain<K1, EditingView[ K1 ], K2, EditingView[ K2 ]>inheritedmodule:engine/view/view~EditingView#bind:DUAL_BINDBinds observable properties to other objects implementing the
Observableinterface.Read more in the dedicated guide covering the topic of property bindings with some additional examples.
Consider two objects: a
buttonand an associatedcommand(bothObservable).A simple property binding could be as follows:
button.bind( 'isEnabled' ).to( command, 'isEnabled' );Copy codeor even shorter:
button.bind( 'isEnabled' ).to( command );Copy codewhich works in the following way:
button.isEnabledinstantly equalscommand.isEnabled,- whenever 
command.isEnabledchanges,button.isEnabledwill immediately reflect its value. 
Note: To release the binding, use
unbind.You can also "rename" the property in the binding by specifying the new name in the
to()chain:button.bind( 'isEnabled' ).to( command, 'isWorking' );Copy codeIt is possible to bind more than one property at a time to shorten the code:
button.bind( 'isEnabled', 'value' ).to( command );Copy codewhich corresponds to:
button.bind( 'isEnabled' ).to( command ); button.bind( 'value' ).to( command );Copy codeThe binding can include more than one observable, combining multiple data sources in a custom callback:
button.bind( 'isEnabled' ).to( command, 'isEnabled', ui, 'isVisible', ( isCommandEnabled, isUIVisible ) => isCommandEnabled && isUIVisible );Copy codeUsing a custom callback allows processing the value before passing it to the target property:
button.bind( 'isEnabled' ).to( command, 'value', value => value === 'heading1' );Copy codeIt is also possible to bind to the same property in an array of observables. To bind a
buttonto multiple commands (alsoObservables) so that each and every one of them must be enabled for the button to become enabled, use the following code:button.bind( 'isEnabled' ).toMany( [ commandA, commandB, commandC ], 'isEnabled', ( isAEnabled, isBEnabled, isCEnabled ) => isAEnabled && isBEnabled && isCEnabled );Copy codeType parameters
K1K2
Parameters
bindProperty1 : K1Observable property that will be bound to other observable(s).
bindProperty2 : K2Observable property that will be bound to other observable(s).
Returns
ObservableDualBindChain<K1, EditingView[ K1 ], K2, EditingView[ K2 ]>The bind chain with the
to()andtoMany()methods.
bind( bindProperty ) → ObservableSingleBindChain<K, EditingView[ K ]>inheritedmodule:engine/view/view~EditingView#bind:SINGLE_BINDBinds observable properties to other objects implementing the
Observableinterface.Read more in the dedicated guide covering the topic of property bindings with some additional examples.
Consider two objects: a
buttonand an associatedcommand(bothObservable).A simple property binding could be as follows:
button.bind( 'isEnabled' ).to( command, 'isEnabled' );Copy codeor even shorter:
button.bind( 'isEnabled' ).to( command );Copy codewhich works in the following way:
button.isEnabledinstantly equalscommand.isEnabled,- whenever 
command.isEnabledchanges,button.isEnabledwill immediately reflect its value. 
Note: To release the binding, use
unbind.You can also "rename" the property in the binding by specifying the new name in the
to()chain:button.bind( 'isEnabled' ).to( command, 'isWorking' );Copy codeIt is possible to bind more than one property at a time to shorten the code:
button.bind( 'isEnabled', 'value' ).to( command );Copy codewhich corresponds to:
button.bind( 'isEnabled' ).to( command ); button.bind( 'value' ).to( command );Copy codeThe binding can include more than one observable, combining multiple data sources in a custom callback:
button.bind( 'isEnabled' ).to( command, 'isEnabled', ui, 'isVisible', ( isCommandEnabled, isUIVisible ) => isCommandEnabled && isUIVisible );Copy codeUsing a custom callback allows processing the value before passing it to the target property:
button.bind( 'isEnabled' ).to( command, 'value', value => value === 'heading1' );Copy codeIt is also possible to bind to the same property in an array of observables. To bind a
buttonto multiple commands (alsoObservables) so that each and every one of them must be enabled for the button to become enabled, use the following code:button.bind( 'isEnabled' ).toMany( [ commandA, commandB, commandC ], 'isEnabled', ( isAEnabled, isBEnabled, isCEnabled ) => isAEnabled && isBEnabled && isCEnabled );Copy codeType parameters
K
Parameters
bindProperty : KObservable property that will be bound to other observable(s).
Returns
ObservableSingleBindChain<K, EditingView[ K ]>The bind chain with the
to()andtoMany()methods.
change( callback ) → TReturnmodule:engine/view/view~EditingView#changeThe
change()method is the primary way of changing the view. You should use it to modify any node in the view tree. It makes sure that after all changes are made the view is rendered to the DOM (assuming that the view will be changed inside the callback). It prevents situations when the DOM is updated when the view state is not yet correct. It allows to nest calls one inside another and still performs a single rendering after all those changes are made. It also returns the return value of its callback.const text = view.change( writer => { const newText = writer.createText( 'foo' ); writer.insert( position1, newText ); view.change( writer => { writer.insert( position2, writer.createText( 'bar' ) ); } ); writer.remove( range ); return newText; } );Copy codeWhen the outermost change block is done and rendering to the DOM is over the
View#renderevent is fired.This method throws a
applying-view-changes-on-renderingerror when the change block is used after rendering to the DOM has started.Type parameters
TReturn
Parameters
callback : ( writer: ViewDowncastWriter ) => TReturnCallback function which may modify the view.
Returns
TReturnValue returned by the callback.
createPositionAfter( item ) → ViewPositionmodule:engine/view/view~EditingView#createPositionAfterCreates a new position after given view item.
Parameters
item : ViewItemView item after which the position should be located.
Returns
createPositionAt( itemOrPosition, [ offset ] ) → ViewPositionmodule:engine/view/view~EditingView#createPositionAtCreates position at the given location. The location can be specified as:
- a position,
 - parent element and offset (offset defaults to 
0), - parent element and 
'end'(sets position at the end of that element), - view item and 
'before'or'after'(sets position before or after given view item). 
This method is a shortcut to other constructors such as:
Parameters
itemOrPosition : ViewPosition | ViewItem[ offset ] : ViewPositionOffsetOffset or one of the flags. Used only when first parameter is a view item.
Returns
createPositionBefore( item ) → ViewPositionmodule:engine/view/view~EditingView#createPositionBeforeCreates a new position before given view item.
Parameters
item : ViewItemView item before which the position should be located.
Returns
createRange( start, [ end ] ) → ViewRangemodule:engine/view/view~EditingView#createRangeCreates a range spanning from
startposition toendposition.Note: This factory method creates it's own
ViewPositioninstances basing on passed values.Parameters
start : ViewPositionStart position.
[ end ] : null | ViewPositionEnd position. If not set, range will be collapsed at
startposition.
Returns
createRangeIn( element ) → ViewRangemodule:engine/view/view~EditingView#createRangeInCreates a range inside an element which starts before the first child of that element and ends after the last child of that element.
Parameters
element : ViewElementElement which is a parent for the range.
Returns
createRangeOn( item ) → ViewRangemodule:engine/view/view~EditingView#createRangeOncreateSelection( [ selectable ], [ options ] ) → ViewSelectionmodule:engine/view/view~EditingView#createSelection:SELECTABLECreates new
ViewSelectioninstance.// Creates empty selection without ranges. const selection = view.createSelection(); // Creates selection at the given range. const range = view.createRange( start, end ); const selection = view.createSelection( range ); // Creates selection at the given ranges const ranges = [ view.createRange( start1, end2 ), view.createRange( star2, end2 ) ]; const selection = view.createSelection( ranges ); // Creates selection from the other selection. const otherSelection = view.createSelection(); const selection = view.createSelection( otherSelection ); // Creates selection from the document selection. const selection = view.createSelection( editor.editing.view.document.selection ); // Creates selection at the given position. const position = view.createPositionFromPath( root, path ); const selection = view.createSelection( position );Copy codeSelection's factory method allow passing additional options (backward,fakeandlabel) as the last argument.// Creates backward selection. const selection = view.createSelection( range, { backward: true } );Copy codeFake selection does not render as browser native selection over selected elements and is hidden to the user. This way, no native selection UI artifacts are displayed to the user and selection over elements can be represented in other way, for example by applying proper CSS class.
Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM (and be properly handled by screen readers).
// Creates fake selection with label. const selection = view.createSelection( range, { fake: true, label: 'foo' } );Copy codeSee also:
createSelection( node, placeOrOffset, options ).Parameters
[ selectable ] : null | ViewPosition | ViewRange | ViewSelection | ViewDocumentSelection | Iterable<ViewRange>[ options ] : ViewSelectionOptions
Returns
createSelection( selectable, placeOrOffset, [ options ] ) → ViewSelectionmodule:engine/view/view~EditingView#createSelection:NODE_OFFSETCreates new
ViewSelectioninstance.// Creates collapsed selection at the position of given item and offset. const paragraph = view.createContainerElement( 'paragraph' ); const selection = view.createSelection( paragraph, offset ); // Creates a range inside an element which starts before the // first child of that element and ends after the last child of that element. const selection = view.createSelection( paragraph, 'in' ); // Creates a range on an item which starts before the item and ends // just after the item. const selection = view.createSelection( paragraph, 'on' );Copy codeSelection's factory method allow passing additional options (backward,fakeandlabel) as the last argument.// Creates backward selection. const selection = view.createSelection( paragraph, 'in', { backward: true } );Copy codeFake selection does not render as browser native selection over selected elements and is hidden to the user. This way, no native selection UI artifacts are displayed to the user and selection over elements can be represented in other way, for example by applying proper CSS class.
Additionally fake's selection label can be provided. It will be used to describe fake selection in DOM (and be properly handled by screen readers).
// Creates fake selection with label. const selection = view.createSelection( element, 'in', { fake: true, label: 'foo' } );Copy codeSee also:
createSelection( selectable, options ).Parameters
selectable : ViewNodeplaceOrOffset : ViewPlaceOrOffset[ options ] : ViewSelectionOptions
Returns
decorate( methodName ) → voidinheritedmodule:engine/view/view~EditingView#decorateTurns the given methods of this object into event-based ones. This means that the new method will fire an event (named after the method) and the original action will be plugged as a listener to that event.
Read more in the dedicated guide covering the topic of decorating methods with some additional examples.
Decorating the method does not change its behavior (it only adds an event), but it allows to modify it later on by listening to the method's event.
For example, to cancel the method execution the event can be stopped:
class Foo extends ObservableMixin() { constructor() { super(); this.decorate( 'method' ); } method() { console.log( 'called!' ); } } const foo = new Foo(); foo.on( 'method', ( evt ) => { evt.stop(); }, { priority: 'high' } ); foo.method(); // Nothing is logged.Copy codeNote: The high priority listener has been used to execute this particular callback before the one which calls the original method (which uses the "normal" priority).
It is also possible to change the returned value:
foo.on( 'method', ( evt ) => { evt.return = 'Foo!'; } ); foo.method(); // -> 'Foo'Copy codeFinally, it is possible to access and modify the arguments the method is called with:
method( a, b ) { console.log( `${ a }, ${ b }` ); } // ... foo.on( 'method', ( evt, args ) => { args[ 0 ] = 3; console.log( args[ 1 ] ); // -> 2 }, { priority: 'high' } ); foo.method( 1, 2 ); // -> '3, 2'Copy codeParameters
methodName : 'off' | 'set' | 'bind' | 'unbind' | 'decorate' | 'stopListening' | 'on' | 'once' | 'listenTo' | 'fire' | 'delegate' | 'stopDelegating' | 'change' | 'focus' | 'document' | 'destroy' | 'createPositionAt' | 'createPositionAfter' | 'createPositionBefore' | 'createRange' | 'createRangeIn' | 'createRangeOn' | 'createSelection' | 'domConverter' | 'domRoots' | 'isRenderingInProgress' | 'hasDomSelection' | 'attachDomRoot' | 'detachDomRoot' | 'getDomRoot' | 'addObserver' | 'getObserver' | 'disableObservers' | 'enableObservers' | 'scrollToTheSelection' | 'forceRender' | '_disableRendering'Name of the method to decorate.
Returns
void
delegate( events ) → EmitterMixinDelegateChaininheritedmodule:engine/view/view~EditingView#delegateDelegates selected events to another
Emitter. For instance:emitterA.delegate( 'eventX' ).to( emitterB ); emitterA.delegate( 'eventX', 'eventY' ).to( emitterC );Copy codethen
eventXis delegated (fired by)emitterBandemitterCalong withdata:emitterA.fire( 'eventX', data );Copy codeand
eventYis delegated (fired by)emitterCalong withdata:emitterA.fire( 'eventY', data );Copy codeParameters
events : Array<string>Event names that will be delegated to another emitter.
Returns
destroy() → voidmodule:engine/view/view~EditingView#destroyDestroys this instance. Makes sure that all observers are destroyed and listeners removed.
Returns
void
detachDomRoot( name ) → voidmodule:engine/view/view~EditingView#detachDomRootDetaches a DOM root element from the view element and restores its attributes to the state before
attachDomRoot().Parameters
name : stringName of the root to detach.
Returns
void
disableObservers() → voidmodule:engine/view/view~EditingView#disableObserversenableObservers() → voidmodule:engine/view/view~EditingView#enableObserversfire( eventOrInfo, args ) → GetEventInfo<TEvent>[ 'return' ]inheritedmodule:engine/view/view~EditingView#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).
focus() → voidmodule:engine/view/view~EditingView#focusIt will focus DOM element representing ViewEditableElement that is currently having selection inside.
Returns
void
forceRender() → voidmodule:engine/view/view~EditingView#forceRenderForces rendering view document to DOM. If any view changes are currently in progress, rendering will start after all change blocks are processed.
Note that this method is dedicated for special cases. All view changes should be wrapped in the
changeblock and the view will automatically check whether it needs to render DOM or not.Throws CKEditorError
applying-view-changes-on-renderingwhen trying to re-render when rendering to DOM has already started.Returns
void
getDomRoot( name ) → undefined | HTMLElementmodule:engine/view/view~EditingView#getDomRootGets DOM root element.
Parameters
name : stringName of the root.
Defaults to
'main'
Returns
undefined | HTMLElementDOM root element instance.
getObserver( ObserverConstructor ) → objectmodule:engine/view/view~EditingView#getObserverType parameters
T : extends ObserverConstructor
Parameters
ObserverConstructor : TThe constructor of an observer to get.
Returns
objectObserver instance or undefined.
listenTo( emitter, event, callback, [ options ] ) → voidinheritedmodule:engine/view/view~EditingView#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.// 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' );Copy codeAn 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:engine/view/view~EditingView#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:engine/view/view~EditingView#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:engine/view/view~EditingView#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
scrollToTheSelection( options = { [options.alignToTop], [options.ancestorOffset], [options.forceScroll], [options.viewportOffset] } ) → voidmodule:engine/view/view~EditingView#scrollToTheSelectionScrolls the page viewport and
domRootswith their ancestors to reveal the caret, if not already visible to the user.Note: Calling this method fires the
ViewScrollToTheSelectionEventevent that allows custom behaviors.Type parameters
T : extends booleanU : extends true
Parameters
options : objectAdditional configuration of the scrolling behavior.
Properties[ options.alignToTop ] : TWhen set
true, the DOM selection will be aligned to the top of the viewport if not already visible (seeforceScrollto learn more).[ options.ancestorOffset ] : numberA distance between the DOM selection and scrollable DOM root ancestor(s) to be maintained while scrolling to the selection (default is 20px). Setting this value to
0will reveal the selection precisely at the scrollable ancestor(s) boundary.Defaults to
20[ options.forceScroll ] : UWhen set
true, the DOM selection will be aligned to the top of the viewport and scrollable ancestors whether it is already visible or not. This option will only work whenalignToTopistrue.[ options.viewportOffset ] : number | objectA distance between the DOM selection and the viewport boundary to be maintained while scrolling to the selection (default is 20px). Setting this value to
0will reveal the selection precisely at the viewport boundary.Defaults to
20
Defaults to
{}
Returns
void
set( values ) → voidinheritedmodule:engine/view/view~EditingView#set:OBJECTCreates and sets the value of an observable properties of this object. Such a property becomes a part of the state and is observable.
It accepts a single object literal containing key/value pairs with properties to be set.
This method throws the
observable-set-cannot-overrideerror if the observable instance already has a property with the given property name. This prevents from mistakenly overriding existing properties and methods, but means thatfoo.set( 'bar', 1 )may be slightly slower thanfoo.bar = 1.In TypeScript, those properties should be declared in class using
declarekeyword. In example:public declare myProp1: number; public declare myProp2: string; constructor() { this.set( { 'myProp1: 2, 'myProp2: 'foo' } ); }Copy codeParameters
values : objectAn object with
name=>valuepairs.
Returns
void
set( name, value ) → voidinheritedmodule:engine/view/view~EditingView#set:KEY_VALUECreates and sets the value of an observable property of this object. Such a property becomes a part of the state and is observable.
This method throws the
observable-set-cannot-overrideerror if the observable instance already has a property with the given property name. This prevents from mistakenly overriding existing properties and methods, but means thatfoo.set( 'bar', 1 )may be slightly slower thanfoo.bar = 1.In TypeScript, those properties should be declared in class using
declarekeyword. In example:public declare myProp: number; constructor() { this.set( 'myProp', 2 ); }Copy codeType parameters
K
Parameters
name : KThe property's name.
value : EditingView[ K ]The property's value.
Returns
void
stopDelegating( [ event ], [ emitter ] ) → voidinheritedmodule:engine/view/view~EditingView#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:engine/view/view~EditingView#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
unbind( unbindProperties ) → voidinheritedmodule:engine/view/view~EditingView#unbindRemoves the binding created with
bind.// Removes the binding for the 'a' property. A.unbind( 'a' ); // Removes bindings for all properties. A.unbind();Copy codeParameters
unbindProperties : Array<'off' | 'set' | 'bind' | 'unbind' | 'decorate' | 'stopListening' | 'on' | 'once' | 'listenTo' | 'fire' | 'delegate' | 'stopDelegating' | 'change' | 'focus' | 'document' | 'destroy' | 'createPositionAt' | 'createPositionAfter' | 'createPositionBefore' | 'createRange' | 'createRangeIn' | 'createRangeOn' | 'createSelection' | 'domConverter' | 'domRoots' | 'isRenderingInProgress' | 'hasDomSelection' | 'attachDomRoot' | 'detachDomRoot' | 'getDomRoot' | 'addObserver' | 'getObserver' | 'disableObservers' | 'enableObservers' | 'scrollToTheSelection' | 'forceRender' | '_disableRendering'>Observable properties to be unbound. All the bindings will be released if no properties are provided.
Returns
void
_disableRendering( flag ) → voidinternalmodule:engine/view/view~EditingView#_disableRenderingDisables or enables rendering. If the flag is set to
truethen the rendering will be disabled. If the flag is set tofalseand if there was some change in the meantime, then the rendering action will be performed.Parameters
flag : booleanA flag indicates whether the rendering should be disabled.
Returns
void
_render() → voidprivatemodule:engine/view/view~EditingView#_renderRenders all changes. In order to avoid triggering the observers (e.g. selection) all observers are disabled before rendering and re-enabled after that.
Returns
void
Events
change:hasDomSelection( eventInfo, name, value, oldValue )module:engine/view/view~EditingView#event:change:hasDomSelectionFired when the
hasDomSelectionproperty changed value.Parameters
eventInfo : EventInfoAn object containing information about the fired event.
name : stringName of the changed property (
hasDomSelection).value : booleanNew value of the
hasDomSelectionproperty with given key ornull, if operation should remove property.oldValue : booleanOld value of the
hasDomSelectionproperty with given key ornull, if property was not set before.
change:isRenderingInProgress( eventInfo, name, value, oldValue )module:engine/view/view~EditingView#event:change:isRenderingInProgressFired when the
isRenderingInProgressproperty changed value.Parameters
eventInfo : EventInfoAn object containing information about the fired event.
name : stringName of the changed property (
isRenderingInProgress).value : booleanNew value of the
isRenderingInProgressproperty with given key ornull, if operation should remove property.oldValue : booleanOld value of the
isRenderingInProgressproperty with given key ornull, if property was not set before.
change:{property}( eventInfo, name, value, oldValue )inheritedmodule:engine/view/view~EditingView#event:change:{property}Fired when a property changed value.
observable.set( 'prop', 1 ); observable.on<ObservableChangeEvent<number>>( 'change:prop', ( evt, propertyName, newValue, oldValue ) => { console.log( `${ propertyName } has changed from ${ oldValue } to ${ newValue }` ); } ); observable.prop = 2; // -> 'prop has changed from 1 to 2'Copy codeParameters
eventInfo : EventInfoAn object containing information about the fired event.
name : stringThe property name.
value : TValueThe new property value.
oldValue : TValueThe previous property value.
render( eventInfo )module:engine/view/view~EditingView#event:renderFired after a topmost change block and all post-fixers are executed.
Actual rendering is performed as a first listener on 'normal' priority.
view.on( 'render', () => { // Rendering to the DOM is complete. } );Copy codeThis event is useful when you want to update interface elements after the rendering, e.g. position of the balloon panel. If you wants to change view structure use post-fixers.
Parameters
eventInfo : EventInfoAn object containing information about the fired event.
scrollToTheSelection( eventInfo, <anonymous>, <anonymous> )module:engine/view/view~EditingView#event:scrollToTheSelectionAn event fired at the moment of
scrollToTheSelectionbeing called. It carries two objects in its payload (args):- The first argument is the object containing data that gets passed down to the 
scrollViewportToShowTargethelper. If some event listener modifies it, it can adjust the behavior of the scrolling (e.g. include additionalviewportOffset). - The second argument corresponds to the original arguments passed to 
scrollViewportToShowTarget. It allows listeners to re-execute thescrollViewportToShowTarget()method with its original arguments if there is such a need, for instance, if the integration requires re–scrolling after certain interaction. 
Parameters
eventInfo : EventInfoAn object containing information about the fired event.
<anonymous> : ViewScrollToTheSelectionEventData<anonymous> : Parameters<EditingView[ 'scrollToTheSelection' ]>[ 0 ]
- The first argument is the object containing data that gets passed down to the 
 set:hasDomSelection( eventInfo, name, value, oldValue )module:engine/view/view~EditingView#event:set:hasDomSelectionFired when the
hasDomSelectionproperty is going to be set but is not set yet (before thechangeevent is fired).Parameters
eventInfo : EventInfoAn object containing information about the fired event.
name : stringName of the changed property (
hasDomSelection).value : booleanNew value of the
hasDomSelectionproperty with given key ornull, if operation should remove property.oldValue : booleanOld value of the
hasDomSelectionproperty with given key ornull, if property was not set before.
set:isRenderingInProgress( eventInfo, name, value, oldValue )module:engine/view/view~EditingView#event:set:isRenderingInProgressFired when the
isRenderingInProgressproperty is going to be set but is not set yet (before thechangeevent is fired).Parameters
eventInfo : EventInfoAn object containing information about the fired event.
name : stringName of the changed property (
isRenderingInProgress).value : booleanNew value of the
isRenderingInProgressproperty with given key ornull, if operation should remove property.oldValue : booleanOld value of the
isRenderingInProgressproperty with given key ornull, if property was not set before.
set:{property}( eventInfo, name, value, oldValue )inheritedmodule:engine/view/view~EditingView#event:set:{property}Fired when a property value is going to be set but is not set yet (before the
changeevent is fired).You can control the final value of the property by using the event's
returnproperty.observable.set( 'prop', 1 ); observable.on<ObservableSetEvent<number>>( 'set:prop', ( evt, propertyName, newValue, oldValue ) => { console.log( `Value is going to be changed from ${ oldValue } to ${ newValue }` ); console.log( `Current property value is ${ observable[ propertyName ] }` ); // Let's override the value. evt.return = 3; } ); observable.on<ObservableChangeEvent<number>>( 'change:prop', ( evt, propertyName, newValue, oldValue ) => { console.log( `Value has changed from ${ oldValue } to ${ newValue }` ); } ); observable.prop = 2; // -> 'Value is going to be changed from 1 to 2' // -> 'Current property value is 1' // -> 'Value has changed from 1 to 3'Copy codeNote: The event is fired even when the new value is the same as the old value.
Parameters
eventInfo : EventInfoAn object containing information about the fired event.
name : stringThe property name.
value : TValueThe new property value.
oldValue : TValueThe previous property value.