Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1118 from ckeditor/t/1117
Browse files Browse the repository at this point in the history
Fix: `AttributeElement`s created by selection conversion were not merged with `AttributeElement`s created by markers conversion. Closes #1117.
  • Loading branch information
szymonkups authored Sep 1, 2017
2 parents b71adfb + cd7ab62 commit e6c5bcf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/conversion/model-selection-to-view-converters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
30 changes: 27 additions & 3 deletions tests/conversion/model-selection-to-view-converters.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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() );
Expand Down Expand Up @@ -293,6 +293,30 @@ describe( 'model-selection-to-view-converters', () => {
.to.equal( '<div>foo<span class="marker2">[]</span>bar</div>' );
} );

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( '<div>f<span class="marker2">oo{}ba</span>r</div>' );
} );

it( 'should do nothing if creator return null', () => {
dispatcher.on( 'selectionMarker:marker3', convertSelectionMarker( () => {

Expand Down

0 comments on commit e6c5bcf

Please sign in to comment.