浏览代码

Fixed: Markers manual test.
Tests: Removed failing test for functionallity that is not possible at this moment to implement.

Szymon Cofalik 9 年之前
父节点
当前提交
a9ee00b7b9

+ 9 - 3
packages/ckeditor5-engine/src/conversion/model-to-view-converters.js

@@ -192,7 +192,7 @@ export function removeAttribute( attributeCreator ) {
  *			|- c                                          |- c
  *
  * The wrapping node depends on passed parameter. If {@link module:engine/view/element~Element} was passed, it will be cloned and
- * the copy will become the wrapping element. If `Function` is provided, it is passed all the parameters of the
+ * the copy will become the wrapping element. If `Function` is provided, it is passed attribute value and then all the parameters of the
  * {@link module:engine/conversion/modelconversiondispatcher~ModelConversionDispatcher#event:addAttribute addAttribute event}.
  * It's expected that the function returns a {@link module:engine/view/element~Element}.
  * The result of the function will be the wrapping element.
@@ -271,7 +271,13 @@ export function unwrapItem( elementCreator ) {
 }
 
 /**
- * Function factory, creates a converter that converts new model marker to view attribute element.
+ * Function factory, creates a converter that wraps model range.
+ *
+ * In contrary to {@link module:engine/conversion/model-to-view-converters~wrapItem}, this converter's input is a
+ * {@link module:engine/model/range~Range model range} (not changed model item). The model range is mapped
+ * to {@link module:engine/view/range~Range view range} and then, view items within that view range are wrapped in a
+ * {@link module:engine/view/attributeelement~AttributeElement view attribute element}. Note, that `elementCreator`
+ * function of this converter takes different parameters that `elementCreator` of `wrapItem`.
  *
  * Let's assume following model and view. `{}` represents a range that is added as a marker with `searchResult` name.
  * The range represents a result of search `ab` string in the model document. The range has to be visualized in view.
@@ -525,7 +531,7 @@ export function moveInOutOfMarker( markersCollection ) {
 
 			if ( wasInMarker && !isInMarker ) {
 				conversionApi.dispatcher.convertMarker( 'removeMarker', name, movedRange );
-			} else if ( !wasInMarker && isInMarker ) {
+			} else if ( isInMarker ) {
 				conversionApi.dispatcher.convertMarker( 'addMarker', name, movedRange );
 			}
 		}

+ 0 - 26
packages/ckeditor5-engine/tests/controller/editingcontroller.js

@@ -406,32 +406,6 @@ describe( 'EditingController', () => {
 
 			editing.modelToView.convertMarker.restore();
 		} );
-
-		it( 'should not start marker conversion if content is moved inside the marker', () => {
-			model.enqueueChanges( () => {
-				model.batch().insert( ModelPosition.createAt( model.getRoot(), 'end' ), new ModelElement( 'paragraph' ) );
-			} );
-
-			const markerRange = ModelLiveRange.createFromParentsAndOffsets( modelRoot, 0, modelRoot, 4 );
-			const consumableMock = {
-				consume: () => true,
-				test: () => true
-			};
-
-			model.markers.add( 'name', markerRange );
-
-			sinon.spy( editing.modelToView, 'convertMarker' );
-
-			editing.modelToView.fire( 'move', {
-				sourcePosition: ModelPosition.createAt( modelRoot, 3 ),
-				targetPosition: ModelPosition.createAt( modelRoot, 1 ),
-				item: modelRoot.getChild( 1 )
-			}, consumableMock, { dispatcher: editing.modelToView, mapper: editing.mapper } );
-
-			expect( editing.modelToView.convertMarker.called ).to.be.false;
-
-			editing.modelToView.convertMarker.restore();
-		} );
 	} );
 
 	describe( 'destroy', () => {

+ 20 - 10
packages/ckeditor5-engine/tests/manual/tickets/643/1.js

@@ -48,23 +48,30 @@ ClassicEditor.create( document.querySelector( '#editor' ), {
 	model.enqueueChanges( () => {
 		const root = model.getRoot();
 		const range = new LiveRange( new Position( root, [ 0, 10 ] ), new Position( root, [ 0, 16 ] ) );
+		const name = 'highlight:yellow:' + uid();
 
-		ranges.push( range );
-		model.markers.addRange( range, 'highlight:yellow' );
+		markerNames.push( name );
+		model.markers.add( name, range );
 	} );
 } )
 .catch( err => {
 	console.error( err.stack );
 } );
 
-const ranges = [];
+const markerNames = [];
+let _uid = 1;
+
+function uid() {
+	return _uid++;
+}
 
 function addHighlight( color ) {
 	model.enqueueChanges( () => {
 		const range = LiveRange.createFromRange( model.selection.getFirstRange() );
+		const name = 'highlight:' + color + ':' + uid();
 
-		ranges.push( range );
-		model.markers.addRange( range, 'highlight:' + color );
+		markerNames.push( name );
+		model.markers.add( name, range );
 	} );
 }
 
@@ -72,12 +79,15 @@ function removeHighlight() {
 	model.enqueueChanges( () => {
 		const pos = model.selection.getFirstPosition();
 
-		for ( let i = 0; i < ranges.length; i++ ) {
-			if ( ranges[ i ].containsPosition( pos ) || ranges[ i ].start.isEqual( pos ) || ranges[ i ].end.isEqual( pos ) ) {
-				model.markers.removeRange( ranges[ i ] );
+		for ( let i = 0; i < markerNames.length; i++ ) {
+			const name = markerNames[ i ];
+			const range = model.markers.get( name );
+
+			if ( range.containsPosition( pos ) || range.start.isEqual( pos ) || range.end.isEqual( pos ) ) {
+				model.markers.remove( name );
+				range.detach();
 
-				ranges[ i ].detach();
-				ranges.splice( i, 1 );
+				markerNames.splice( i, 1 );
 				break;
 			}
 		}