8
0
Просмотр исходного кода

Aligned manual tests with engine chamges.

Oskar Wróbel 8 лет назад
Родитель
Сommit
f243792322

+ 8 - 13
packages/ckeditor5-engine/tests/manual/highlight.js

@@ -32,8 +32,7 @@ class FancyWidget extends Plugin {
 
 	init() {
 		const editor = this.editor;
-		const doc = editor.document;
-		const schema = doc.schema;
+		const schema = editor.model.schema;
 		const data = editor.data;
 		const editing = editor.editing;
 
@@ -101,9 +100,9 @@ ClassicEditor.create( global.document.querySelector( '#editor' ), {
 		} );
 
 		document.getElementById( 'remove-markers' ).addEventListener( 'mousedown', evt => {
-			const markers = editor.document.markers;
+			const markers = editor.model.markers;
 
-			editor.document.enqueueChanges( () => {
+			editor.model.change( () => {
 				for ( const marker of markers ) {
 					markers.remove( marker );
 				}
@@ -117,18 +116,14 @@ ClassicEditor.create( global.document.querySelector( '#editor' ), {
 	} );
 
 function addMarker( editor, color ) {
-	const model = editor.document;
-
-	editor.document.enqueueChanges( () => {
-		const range = ModelRange.createFromRange( model.selection.getFirstRange() );
-		model.markers.set( 'marker:' + color, range );
+	editor.model.change( () => {
+		const range = ModelRange.createFromRange( editor.model.document.selection.getFirstRange() );
+		editor.model.markers.set( 'marker:' + color, range );
 	} );
 }
 
 function removeMarker( editor, color ) {
-	const model = editor.document;
-
-	editor.document.enqueueChanges( () => {
-		model.markers.remove( 'marker:' + color );
+	editor.model.change( () => {
+		editor.model.markers.remove( 'marker:' + color );
 	} );
 }

+ 13 - 13
packages/ckeditor5-engine/tests/manual/markers.js

@@ -30,7 +30,7 @@ ClassicEditor
 	} )
 	.then( editor => {
 		window.editor = editor;
-		model = window.editor.editing.model;
+		model = editor.model;
 
 		buildModelConverter().for( editor.editing.modelToView )
 			.fromMarker( 'highlight' )
@@ -73,8 +73,8 @@ ClassicEditor
 			moveSelectionByOffset( 1 );
 		} );
 
-		model.enqueueChanges( () => {
-			const root = model.getRoot();
+		model.change( () => {
+			const root = model.document.getRoot();
 			const range = new Range( new Position( root, [ 0, 10 ] ), new Position( root, [ 0, 16 ] ) );
 			const name = 'highlight:yellow:' + uid();
 
@@ -91,8 +91,8 @@ function uid() {
 }
 
 function addHighlight( color ) {
-	model.enqueueChanges( () => {
-		const range = Range.createFromRange( model.selection.getFirstRange() );
+	model.change( () => {
+		const range = Range.createFromRange( model.document.selection.getFirstRange() );
 		const name = 'highlight:' + color + ':' + uid();
 
 		markerNames.push( name );
@@ -101,8 +101,8 @@ function addHighlight( color ) {
 }
 
 function removeHighlight() {
-	model.enqueueChanges( () => {
-		const pos = model.selection.getFirstPosition();
+	model.change( () => {
+		const pos = model.document.selection.getFirstPosition();
 
 		for ( let i = 0; i < markerNames.length; i++ ) {
 			const name = markerNames[ i ];
@@ -120,22 +120,22 @@ function removeHighlight() {
 }
 
 function moveSelectionToStart() {
-	const range = model.selection.getFirstRange();
+	const range = model.document.selection.getFirstRange();
 
 	if ( range.isFlat ) {
-		model.enqueueChanges( () => {
-			model.batch().move( range, new Position( model.getRoot(), [ 0, 0 ] ) );
+		model.change( writer => {
+			writer.move( range, new Position( model.document.getRoot(), [ 0, 0 ] ) );
 		} );
 	}
 }
 
 function moveSelectionByOffset( offset ) {
-	const range = model.selection.getFirstRange();
+	const range = model.document.selection.getFirstRange();
 	const pos = offset < 0 ? range.start : range.end;
 
 	if ( range.isFlat ) {
-		model.enqueueChanges( () => {
-			model.batch().move( range, pos.getShiftedBy( offset ) );
+		model.change( writer => {
+			writer.move( range, pos.getShiftedBy( offset ) );
 		} );
 	}
 }

+ 3 - 4
packages/ckeditor5-engine/tests/manual/nestededitable.js

@@ -23,11 +23,10 @@ import './nestededitable.css';
 class NestedEditable extends Plugin {
 	init() {
 		const editor = this.editor;
-		const document = editor.document;
 		const editing = editor.editing;
 		const viewDocument = editing.view;
 		const data = editor.data;
-		const schema = document.schema;
+		const schema = editor.model.schema;
 
 		schema.registerItem( 'figure' );
 		schema.registerItem( 'figcaption' );
@@ -75,7 +74,7 @@ ClassicEditor
 		toolbar: [ 'undo', 'redo' ]
 	} )
 	.then( editor => {
-		editor.document.on( 'changesDone', () => {
+		editor.model.document.on( 'changesDone', () => {
 			printModelContents( editor );
 		} );
 
@@ -87,5 +86,5 @@ ClassicEditor
 
 const modelDiv = global.document.querySelector( '#model' );
 function printModelContents( editor ) {
-	modelDiv.innerText = getData( editor.document );
+	modelDiv.innerText = getData( editor.model );
 }

+ 1 - 1
packages/ckeditor5-engine/tests/manual/tickets/1088/1.js

@@ -19,7 +19,7 @@ ClassicEditor
 	.then( editor => {
 		window.editor = editor;
 
-		const schema = editor.document.schema;
+		const schema = editor.model.schema;
 
 		schema.disallow( { name: '$text', attributes: [ 'linkHref', 'italic' ], inside: 'heading1' } );
 		schema.disallow( { name: '$text', attributes: [ 'italic' ], inside: 'heading2' } );

+ 2 - 2
packages/ckeditor5-engine/tests/manual/tickets/462/1.js

@@ -27,8 +27,8 @@ ClassicEditor
 			const selectionExists = domSelection && domSelection.anchorNode;
 
 			console.log( editor.editing.view.getDomRoot().innerHTML.replace( /\u200b/g, '@' ) );
-			console.log( 'selection.hasAttribute( italic ):', editor.document.selection.hasAttribute( 'italic' ) );
-			console.log( 'selection.hasAttribute( bold ):', editor.document.selection.hasAttribute( 'bold' ) );
+			console.log( 'selection.hasAttribute( italic ):', editor.model.document.selection.hasAttribute( 'italic' ) );
+			console.log( 'selection.hasAttribute( bold ):', editor.model.document.selection.hasAttribute( 'bold' ) );
 			console.log( 'selection anchor\'s parentNode:', selectionExists ? domSelection.anchorNode.parentNode : 'no DOM selection' );
 		}, 2000 );
 	} )

+ 4 - 5
packages/ckeditor5-engine/tests/manual/tickets/475/1.js

@@ -31,7 +31,7 @@ class Link extends Plugin {
 		const editing = editor.editing;
 
 		// Allow bold attribute on all inline nodes.
-		editor.document.schema.allow( { name: '$inline', attributes: [ 'link' ] } );
+		editor.model.schema.allow( { name: '$inline', attributes: [ 'link' ] } );
 
 		// Build converter from model to view for data and editing pipelines.
 		buildModelConverter().for( data.modelToView, editing.modelToView )
@@ -49,7 +49,7 @@ const urlRegex = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b(
 
 class AutoLinker extends Plugin {
 	init() {
-		this.editor.document.on( 'change', ( event, type, changes, batch ) => {
+		this.editor.model.document.on( 'change', ( event, type, changes, batch ) => {
 			if ( type != 'insert' ) {
 				return;
 			}
@@ -73,14 +73,13 @@ class AutoLinker extends Plugin {
 					return;
 				}
 
-				const doc = this.editor.document;
 				const url = matchedUrl[ 0 ];
 				const offset = _getLastPathPart( currentValue.nextPosition.path ) + matchedUrl.index;
 				const livePos = LivePosition.createFromParentAndOffset( currentValue.item.parent, offset );
 
-				doc.enqueueChanges( () => {
+				this.editor.model.enqueueChange( batch, writer => {
 					const urlRange = Range.createFromPositionAndShift( livePos, url.length );
-					batch.setAttribute( 'link', url, urlRange );
+					writer.setAttribute( 'link', url, urlRange );
 				} );
 			}
 		} );

+ 1 - 1
packages/ckeditor5-engine/tests/manual/tickets/603/1.js

@@ -21,7 +21,7 @@ ClassicEditor
 	.then( editor => {
 		window.editor = editor;
 
-		const sel = editor.document.selection;
+		const sel = editor.model.document.selection;
 
 		sel.on( 'change', ( evt, data ) => {
 			const date = new Date();

+ 1 - 1
packages/ckeditor5-engine/tests/manual/tickets/880/1.js

@@ -19,7 +19,7 @@ ClassicEditor
 		window.editor = editor;
 
 		editor.editing.view.on( 'selectionChange', () => {
-			editor.document.enqueueChanges( () => {
+			editor.model.change( () => {
 			} );
 			console.log( 'selectionChange', ( new Date() ).getTime() );
 		} );