소스 검색

Aligned code with the engine changes.

Oskar Wróbel 8 년 전
부모
커밋
b9dc0b6735
3개의 변경된 파일19개의 추가작업 그리고 24개의 파일을 삭제
  1. 12 14
      packages/ckeditor5-link/src/linkcommand.js
  2. 2 2
      packages/ckeditor5-link/src/linkengine.js
  3. 5 8
      packages/ckeditor5-link/src/unlinkcommand.js

+ 12 - 14
packages/ckeditor5-link/src/linkcommand.js

@@ -30,10 +30,11 @@ export default class LinkCommand extends Command {
 	 * @inheritDoc
 	 */
 	refresh() {
-		const doc = this.editor.document;
+		const model = this.editor.model;
+		const doc = model.document;
 
 		this.value = doc.selection.getAttribute( 'linkHref' );
-		this.isEnabled = doc.schema.checkAttributeInSelection( doc.selection, 'linkHref' );
+		this.isEnabled = model.schema.checkAttributeInSelection( doc.selection, 'linkHref' );
 	}
 
 	/**
@@ -53,13 +54,10 @@ export default class LinkCommand extends Command {
 	 * @param {String} href Link destination.
 	 */
 	execute( href ) {
-		const doc = this.editor.document;
-		const selection = doc.selection;
-
-		doc.enqueueChanges( () => {
-			// Keep it as one undo step.
-			const batch = doc.batch();
+		const model = this.editor.model;
+		const selection = model.document.selection;
 
+		model.enqueueChange( writer => {
 			// If selection is collapsed then update selected link or insert new one at the place of caret.
 			if ( selection.isCollapsed ) {
 				const position = selection.getFirstPosition();
@@ -69,20 +67,20 @@ export default class LinkCommand extends Command {
 					// Then update `linkHref` value.
 					const linkRange = findLinkRange( selection.getFirstPosition(), selection.getAttribute( 'linkHref' ) );
 
-					batch.setAttribute( 'linkHref', href, linkRange );
+					writer.setAttribute( 'linkHref', href, linkRange );
 
 					// Create new range wrapping changed link.
 					selection.setRanges( [ linkRange ] );
 				}
 				// If not then insert text node with `linkHref` attribute in place of caret.
 				else {
-					const attributes = toMap( doc.selection.getAttributes() );
+					const attributes = toMap( selection.getAttributes() );
 
 					attributes.set( 'linkHref', href );
 
-					const node = batch.createText( href, attributes );
+					const node = writer.createText( href, attributes );
 
-					batch.insert( node, position );
+					writer.insert( node, position );
 
 					// Create new range wrapping created node.
 					selection.setRanges( [ Range.createOn( node ) ] );
@@ -90,10 +88,10 @@ export default class LinkCommand extends Command {
 			} else {
 				// If selection has non-collapsed ranges, we change attribute on nodes inside those ranges
 				// omitting nodes where `linkHref` attribute is disallowed.
-				const ranges = doc.schema.getValidRanges( selection.getRanges(), 'linkHref' );
+				const ranges = model.schema.getValidRanges( selection.getRanges(), 'linkHref' );
 
 				for ( const range of ranges ) {
-					batch.setAttribute( 'linkHref', href, range );
+					writer.setAttribute( 'linkHref', href, range );
 				}
 			}
 		} );

+ 2 - 2
packages/ckeditor5-link/src/linkengine.js

@@ -31,9 +31,9 @@ export default class LinkEngine extends Plugin {
 		const editing = editor.editing;
 
 		// Allow link attribute on all inline nodes.
-		editor.document.schema.allow( { name: '$inline', attributes: 'linkHref', inside: '$block' } );
+		editor.model.schema.allow( { name: '$inline', attributes: 'linkHref', inside: '$block' } );
 		// Temporary workaround. See https://github.com/ckeditor/ckeditor5/issues/477.
-		editor.document.schema.allow( { name: '$inline', attributes: 'linkHref', inside: '$clipboardHolder' } );
+		editor.model.schema.allow( { name: '$inline', attributes: 'linkHref', inside: '$clipboardHolder' } );
 
 		// Build converter from model to view for data and editing pipelines.
 		buildModelConverter().for( data.modelToView, editing.modelToView )

+ 5 - 8
packages/ckeditor5-link/src/unlinkcommand.js

@@ -20,7 +20,7 @@ export default class UnlinkCommand extends Command {
 	 * @inheritDoc
 	 */
 	refresh() {
-		this.isEnabled = this.editor.document.selection.hasAttribute( 'linkHref' );
+		this.isEnabled = this.editor.model.document.selection.hasAttribute( 'linkHref' );
 	}
 
 	/**
@@ -32,20 +32,17 @@ export default class UnlinkCommand extends Command {
 	 * @fires execute
 	 */
 	execute() {
-		const document = this.editor.document;
-		const selection = document.selection;
+		const model = this.editor.model;
+		const selection = model.document.selection;
 
-		document.enqueueChanges( () => {
+		model.enqueueChange( writer => {
 			// Get ranges to unlink.
 			const rangesToUnlink = selection.isCollapsed ?
 				[ findLinkRange( selection.getFirstPosition(), selection.getAttribute( 'linkHref' ) ) ] : selection.getRanges();
 
-			// Keep it as one undo step.
-			const batch = document.batch();
-
 			// Remove `linkHref` attribute from specified ranges.
 			for ( const range of rangesToUnlink ) {
-				batch.removeAttribute( 'linkHref', range );
+				writer.removeAttribute( 'linkHref', range );
 			}
 		} );
 	}