瀏覽代碼

Methods renaming, small fixes in ImageCaption.

Szymon Kupś 8 年之前
父節點
當前提交
30ee96b06b

+ 4 - 4
packages/ckeditor5-image/src/imagecaption/imagecaptionengine.js

@@ -19,7 +19,7 @@ import ModelPosition from '@ckeditor/ckeditor5-engine/src/model/position';
 import buildViewConverter from '@ckeditor/ckeditor5-engine/src/conversion/buildviewconverter';
 import ViewMatcher from '@ckeditor/ckeditor5-engine/src/view/matcher';
 import { isImage, isImageWidget } from '../utils';
-import { editableCaptionCreator, isCaptionEditable, getCaptionFromImage } from './utils';
+import { captionElementCreator, isCaption, getCaptionFromImage } from './utils';
 
 /**
  * The image caption engine plugin.
@@ -81,7 +81,7 @@ export default class ImageCaptionEngine extends Plugin {
 		// Model to view converter for editing pipeline.
 		editing.modelToView.on(
 			'insert:caption',
-			captionModelToView( editableCaptionCreator( viewDocument ) )
+			captionModelToView( captionElementCreator( viewDocument ) )
 		);
 
 		// Adding / removing caption element when there is no text in the model.
@@ -98,7 +98,7 @@ export default class ImageCaptionEngine extends Plugin {
 			// If selection is currently inside caption editable - store it to hide when empty.
 			const editableElement = selection.editableElement;
 
-			if ( editableElement && isCaptionEditable( selection.editableElement ) ) {
+			if ( editableElement && isCaption( selection.editableElement ) ) {
 				this._lastSelectedEditable = selection.editableElement;
 			}
 		}, { priority: 'high' } );
@@ -152,7 +152,7 @@ export default class ImageCaptionEngine extends Plugin {
 		const selection = editing.view.selection;
 		const imageFigure = selection.getSelectedElement();
 		const mapper = editing.mapper;
-		const editableCreator = editableCaptionCreator( editing.view );
+		const editableCreator = captionElementCreator( editing.view );
 
 		if ( imageFigure && isImageWidget( imageFigure ) ) {
 			const modelImage = mapper.toModelElement( imageFigure );

+ 2 - 2
packages/ckeditor5-image/src/imagecaption/utils.js

@@ -18,7 +18,7 @@ const captionSymbol = Symbol( 'imageCaption' );
  * @param {module:engine/view/document~Document} viewDocument
  * @return {Function}
  */
-export function editableCaptionCreator( viewDocument ) {
+export function captionElementCreator( viewDocument ) {
 	return () => {
 		const editable = new ViewEditableElement( 'figcaption', { contenteditable: true } );
 		editable.document = viewDocument;
@@ -42,7 +42,7 @@ export function editableCaptionCreator( viewDocument ) {
  * @param {module:engine/view/element~Element} viewElement
  * @return {Boolean}
  */
-export function isCaptionEditable( viewElement ) {
+export function isCaption( viewElement ) {
 	return !!viewElement.getCustomProperty( captionSymbol );
 }
 

+ 1 - 3
packages/ckeditor5-image/src/widget/widget.js

@@ -65,9 +65,7 @@ export default class Widget extends Plugin {
 		let widgetElement = domEventData.target;
 
 		if ( !isWidget( widgetElement ) ) {
-			widgetElement = widgetElement.findAncestor( element => {
-				return isWidget( element );
-			} );
+			widgetElement = widgetElement.findAncestor( isWidget );
 
 			if ( !widgetElement ) {
 				return;

+ 5 - 5
packages/ckeditor5-image/tests/imagecaption/utils.js

@@ -5,7 +5,7 @@
 
 import ViewDocument from '@ckeditor/ckeditor5-engine/src/view/document';
 import ViewEditableElement from '@ckeditor/ckeditor5-engine/src/view/editableelement';
-import { editableCaptionCreator, isCaptionEditable, getCaptionFromImage } from '../../src/imagecaption/utils';
+import { captionElementCreator, isCaption, getCaptionFromImage } from '../../src/imagecaption/utils';
 import ModelElement from '@ckeditor/ckeditor5-engine/src/model/element';
 
 describe( 'image captioning utils', () => {
@@ -13,7 +13,7 @@ describe( 'image captioning utils', () => {
 
 	beforeEach( () => {
 		document = new ViewDocument();
-		const creator = editableCaptionCreator( document );
+		const creator = captionElementCreator( document );
 		element = creator();
 	} );
 
@@ -21,7 +21,7 @@ describe( 'image captioning utils', () => {
 		it( 'should create figcatpion editable element', () => {
 			expect( element ).to.be.instanceOf( ViewEditableElement );
 			expect( element.name ).to.equal( 'figcaption' );
-			expect( isCaptionEditable( element ) ).to.be.true;
+			expect( isCaption( element ) ).to.be.true;
 		} );
 
 		it( 'should be created in context of proper document', () => {
@@ -39,14 +39,14 @@ describe( 'image captioning utils', () => {
 
 	describe( 'isCaptionEditable', () => {
 		it( 'should return true for elements created with creator', () => {
-			expect( isCaptionEditable( element ) ).to.be.true;
+			expect( isCaption( element ) ).to.be.true;
 		} );
 
 		it( 'should return false for other elements', () => {
 			const editable = new ViewEditableElement( 'figcaption', { contenteditable: true } ) ;
 			editable.document = document;
 
-			expect( isCaptionEditable( editable ) ).to.be.false;
+			expect( isCaption( editable ) ).to.be.false;
 		} );
 	} );