From cd7ab6235c20bda3876951d76a5f9abf251459f9 Mon Sep 17 00:00:00 2001 From: Szymon Cofalik Date: Thu, 31 Aug 2017 13:23:08 +0200 Subject: [PATCH] Changed: `convertSelectionMarker` should use `HighlightDescriptor#id`. --- .../model-selection-to-view-converters.js | 4 +++ .../model-selection-to-view-converters.js | 30 +++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/conversion/model-selection-to-view-converters.js b/src/conversion/model-selection-to-view-converters.js index 96ae39288..71e4d5023 100644 --- a/src/conversion/model-selection-to-view-converters.js +++ b/src/conversion/model-selection-to-view-converters.js @@ -176,6 +176,10 @@ export function convertSelectionMarker( highlightDescriptor ) { return; } + if ( !descriptor.id ) { + descriptor.id = data.markerName; + } + const viewElement = createViewElementFromHighlightDescriptor( descriptor ); const consumableName = 'selectionMarker:' + data.markerName; diff --git a/tests/conversion/model-selection-to-view-converters.js b/tests/conversion/model-selection-to-view-converters.js index 4d7cd12b6..1cda35120 100644 --- a/tests/conversion/model-selection-to-view-converters.js +++ b/tests/conversion/model-selection-to-view-converters.js @@ -36,10 +36,8 @@ import { import { stringify as stringifyView } from '../../src/dev-utils/view'; import { setData as setModelData } from '../../src/dev-utils/model'; -const highlightDescriptor = { class: 'marker', priority: 1 }; - describe( 'model-selection-to-view-converters', () => { - let dispatcher, mapper, modelDoc, modelRoot, modelSelection, viewDoc, viewRoot, viewSelection; + let dispatcher, mapper, modelDoc, modelRoot, modelSelection, viewDoc, viewRoot, viewSelection, highlightDescriptor; beforeEach( () => { modelDoc = new ModelDocument(); @@ -55,6 +53,8 @@ describe( 'model-selection-to-view-converters', () => { mapper = new Mapper(); mapper.bindElements( modelRoot, viewRoot ); + highlightDescriptor = { class: 'marker', priority: 1 }; + dispatcher = new ModelConversionDispatcher( modelDoc, { mapper, viewSelection } ); dispatcher.on( 'insert:$text', insertText() ); @@ -293,6 +293,30 @@ describe( 'model-selection-to-view-converters', () => { .to.equal( '
foo[]bar
' ); } ); + it( 'in marker - should merge with the rest of attribute elements', () => { + dispatcher.on( 'addMarker:marker2', highlightText( data => ( { 'class': data.markerName } ) ) ); + dispatcher.on( 'selectionMarker:marker2', convertSelectionMarker( data => ( { 'class': data.markerName } ) ) ); + + setModelData( modelDoc, 'foobar' ); + const marker = modelDoc.markers.set( 'marker2', ModelRange.createFromParentsAndOffsets( modelRoot, 1, modelRoot, 5 ) ); + + modelSelection.setRanges( [ new ModelRange( ModelPosition.createAt( modelRoot, 3 ) ) ] ); + + // Remove view children manually (without firing additional conversion). + viewRoot.removeChildren( 0, viewRoot.childCount ); + + // Convert model to view. + dispatcher.convertInsertion( ModelRange.createIn( modelRoot ) ); + dispatcher.convertMarker( 'addMarker', marker.name, marker.getRange() ); + + const markers = Array.from( modelDoc.markers.getMarkersAtPosition( modelSelection.getFirstPosition() ) ); + dispatcher.convertSelection( modelSelection, markers ); + + // Stringify view and check if it is same as expected. + expect( stringifyView( viewRoot, viewSelection, { showType: false } ) ) + .to.equal( '
foo{}bar
' ); + } ); + it( 'should do nothing if creator return null', () => { dispatcher.on( 'selectionMarker:marker3', convertSelectionMarker( () => {