Typedef

MapperViewToModelPositionEvent (engine/conversion)

@ckeditor/ckeditor5-engine/src/conversion/mapper

typedefobject

Fired for each view-to-model position mapping request. See event-modelToViewPosition.

// See example in `modelToViewPosition` event description.
// This custom mapping will map positions from <span> element next to <img> to the "captionedImage" element.
mapper.on( 'viewToModelPosition', ( evt, data ) => {
	const positionParent = viewPosition.parent;

	if ( positionParent.hasClass( 'image-caption' ) ) {
		const viewImg = positionParent.previousSibling;
		const modelImg = data.mapper.toModelElement( viewImg );

		data.modelPosition = new ModelPosition( modelImg, viewPosition.offset );
		evt.stop();
	}
} );

Note: the default mapping callback is provided with a low priority setting and does not cancel the event, so it is possible to attach a custom callback after the default callback and also use data.modelPosition calculated by the default callback (for example to fix it).

Note: the default mapping callback will not fire if data.modelPosition is already set.

Note: these callbacks are called very often. For efficiency reasons, it is advised to use them only when position mapping between the given model and view elements is unsolvable by using just elements mapping and default algorithm. Also, the condition that checks if special case scenario happened should be as simple as possible.

Filtering

Properties

  • args : tuple

  • name : 'viewToModelPosition'

Fired by