|
@@ -15,12 +15,11 @@ import {
|
|
|
removeUIElement,
|
|
removeUIElement,
|
|
|
wrapItem,
|
|
wrapItem,
|
|
|
unwrapItem,
|
|
unwrapItem,
|
|
|
- eventNameToConsumableType
|
|
|
|
|
|
|
+ virtualSelectionConverter
|
|
|
} from './model-to-view-converters';
|
|
} from './model-to-view-converters';
|
|
|
|
|
|
|
|
import { convertSelectionAttribute, convertSelectionMarker } from './model-selection-to-view-converters';
|
|
import { convertSelectionAttribute, convertSelectionMarker } from './model-selection-to-view-converters';
|
|
|
|
|
|
|
|
-import ModelRange from '../model/range';
|
|
|
|
|
import ViewAttributeElement from '../view/attributeelement';
|
|
import ViewAttributeElement from '../view/attributeelement';
|
|
|
import ViewContainerElement from '../view/containerelement';
|
|
import ViewContainerElement from '../view/containerelement';
|
|
|
import ViewUIElement from '../view/uielement';
|
|
import ViewUIElement from '../view/uielement';
|
|
@@ -247,93 +246,13 @@ class ModelConverterBuilder {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- toVirtualSelection( selectionInfo ) {
|
|
|
|
|
|
|
+ toVirtualSelection( selectionDescriptor ) {
|
|
|
const priority = this._from.priority === null ? 'normal' : this._from.priority;
|
|
const priority = this._from.priority === null ? 'normal' : this._from.priority;
|
|
|
|
|
|
|
|
for ( const dispatcher of this._dispatchers ) {
|
|
for ( const dispatcher of this._dispatchers ) {
|
|
|
- dispatcher.on( 'selectionMarker:' + this._from.name, ( evt, data, consumable, api ) => {
|
|
|
|
|
- const info = selectionInfo( data );
|
|
|
|
|
- const wrapElement = new ViewAttributeElement( 'span', info.attributes );
|
|
|
|
|
-
|
|
|
|
|
- if ( info.class ) {
|
|
|
|
|
- wrapElement.addClass( info.class );
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- const wrap = convertSelectionMarker( wrapElement );
|
|
|
|
|
-
|
|
|
|
|
- wrap( evt, data, consumable, api );
|
|
|
|
|
- }, { priority } );
|
|
|
|
|
-
|
|
|
|
|
- dispatcher.on( 'addMarker:' + this._from.name, ( evt, data, consumable, api ) => {
|
|
|
|
|
- const modelItem = data.item;
|
|
|
|
|
- const info = selectionInfo( data );
|
|
|
|
|
-
|
|
|
|
|
- if ( modelItem.is( 'textProxy' ) ) {
|
|
|
|
|
- const wrapElement = new ViewAttributeElement( 'span', info.attributes );
|
|
|
|
|
-
|
|
|
|
|
- if ( info.class ) {
|
|
|
|
|
- wrapElement.addClass( info.class );
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- const wrap = wrapItem( wrapElement );
|
|
|
|
|
-
|
|
|
|
|
- wrap( evt, data, consumable, api );
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if ( modelItem.is( 'element' ) ) {
|
|
|
|
|
- const consumableType = eventNameToConsumableType( evt.name );
|
|
|
|
|
- const viewElement = api.mapper.toViewElement( modelItem );
|
|
|
|
|
-
|
|
|
|
|
- if ( !consumable.consume( modelItem, consumableType ) ) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if ( viewElement && viewElement.setVirtualSelection ) {
|
|
|
|
|
- // Virtual selection will be handled by parent element - consume all children.
|
|
|
|
|
- for ( const value of ModelRange.createIn( modelItem ) ) {
|
|
|
|
|
- consumable.consume( value.item, consumableType );
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- viewElement.setVirtualSelection( info );
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }, { priority } );
|
|
|
|
|
-
|
|
|
|
|
- dispatcher.on( 'removeMarker:' + this._from.name, ( evt, data, consumable, api ) => {
|
|
|
|
|
- const modelItem = data.item;
|
|
|
|
|
- const info = selectionInfo( data );
|
|
|
|
|
-
|
|
|
|
|
- if ( modelItem.is( 'textProxy' ) ) {
|
|
|
|
|
- const info = selectionInfo( data );
|
|
|
|
|
- const wrapElement = new ViewAttributeElement( 'span', info.attributes );
|
|
|
|
|
-
|
|
|
|
|
- if ( info.class ) {
|
|
|
|
|
- wrapElement.addClass( info.class );
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- const unwrap = unwrapItem( wrapElement );
|
|
|
|
|
-
|
|
|
|
|
- unwrap( evt, data, consumable, api );
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if ( modelItem.is( 'element' ) ) {
|
|
|
|
|
- const consumableType = eventNameToConsumableType( evt.name );
|
|
|
|
|
- const viewElement = api.mapper.toViewElement( modelItem );
|
|
|
|
|
-
|
|
|
|
|
- if ( !consumable.consume( modelItem, consumableType ) ) {
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- if ( viewElement && viewElement.setVirtualSelection ) {
|
|
|
|
|
- // Virtual selection will be handled by parent element - consume all children.
|
|
|
|
|
- for ( const value of ModelRange.createIn( modelItem ) ) {
|
|
|
|
|
- consumable.consume( value.item, consumableType );
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- viewElement.removeVirtualSelection( info );
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- }, { priority } );
|
|
|
|
|
|
|
+ dispatcher.on( 'addMarker:' + this._from.name, virtualSelectionConverter( selectionDescriptor ), { priority } );
|
|
|
|
|
+ dispatcher.on( 'removeMarker:' + this._from.name, virtualSelectionConverter( selectionDescriptor, false ), { priority } );
|
|
|
|
|
+ dispatcher.on( 'selectionMarker:' + this._from.name, convertSelectionMarker( selectionDescriptor ), { priority } );
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|