# MapperViewToModelPositionEvent

typedef

Fired for each view-to-model position mapping request. See [event-modelToViewPosition](module_engine_conversion_mapper-Mapper.md#event-modelToViewPosition).

```typescript
// 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.

[See source](https://github.com/ckeditor/ckeditor5/blob/master/packages/ckeditor5-engine/src/conversion/mapper.ts#L1395)

<a id="properties">

## Properties

<a id="member-args">

### `args: [ MapperViewToModelPositionEventData ]`

<a id="member-name">

### `name: 'viewToModelPosition'`

#### Value

`object`

## Fired by

* [Mapper#viewToModelPosition](module_engine_conversion_mapper-Mapper.md#event-viewToModelPosition)

---

Full index of the CKEditor 5 API reference: [llms.txt](llms.txt)
