Parcourir la source

Do not prevent from creating trimmed marker before the opening tag.

Oskar Wróbel il y a 6 ans
Parent
commit
7fddc757ea

+ 1 - 3
packages/ckeditor5-heading/src/title.js

@@ -174,10 +174,8 @@ export default class Title extends Plugin {
 		data.downcastDispatcher.convertInsert( rootRange, viewWriter );
 
 		// Convert all markers that intersects with body.
-		// Avoid markers that starts before body, move it to the first selection position.
 		const bodyStartPosition = model.createPositionAfter( root.getChild( 0 ) );
-		const bodySelectionPosition = model.schema.getNearestSelectionRange( bodyStartPosition, 'forward' ).start;
-		const bodyRange = model.createRange( bodySelectionPosition, model.createPositionAt( root, 'end' ) );
+		const bodyRange = model.createRange( bodyStartPosition, model.createPositionAt( root, 'end' ) );
 
 		for ( const marker of model.markers ) {
 			const intersection = bodyRange.getIntersection( marker.getRange() );

+ 22 - 0
packages/ckeditor5-heading/tests/title.js

@@ -566,6 +566,28 @@ describe( 'Title', () => {
 			} );
 
 			expect( editor.plugins.get( 'Title' ).getBody() ).to.equal(
+				'<comment></comment><p>Ba<comment></comment>r</p>'
+			);
+		} );
+
+		it( 'should return marker - starts at the beginning of the body ends inside the body', () => {
+			editor.conversion.for( 'downcast' ).markerToElement( { model: 'comment', view: 'comment' } );
+
+			setData( model,
+				'<title><title-content>Foo</title-content></title>' +
+				'<paragraph>Bar</paragraph>'
+			);
+
+			const body = model.document.getRoot().getChild( 1 );
+
+			model.change( writer => {
+				writer.addMarker( 'comment', {
+					range: model.createRange( model.createPositionAt( body, 0 ), model.createPositionAt( body, 2 ) ),
+					usingOperation: true
+				} );
+			} );
+
+			expect( editor.plugins.get( 'Title' ).getBody() ).to.equal(
 				'<p><comment></comment>Ba<comment></comment>r</p>'
 			);
 		} );