Jelajahi Sumber

Simple code and docs improvements related to requests from review.

Mateusz Samsel 6 tahun lalu
induk
melakukan
e09e98599c

+ 7 - 6
packages/ckeditor5-link/src/linkcommand.js

@@ -31,7 +31,7 @@ export default class LinkCommand extends Command {
 
 		/**
 		 * Keeps collection of {@link module:link/utils~ManualDecorator}
-		 * recognized from {@link module:link/link~LinkConfig#decorators}.
+		 * corresponding to {@link module:link/link~LinkConfig#decorators}.
 		 * You can consider it as a model of states for custom attributes added to links.
 		 *
 		 * @readonly
@@ -79,13 +79,14 @@ export default class LinkCommand extends Command {
 		// Stores information about custom attributes to turn on/off.
 		const truthyCustomAttributes = [];
 		const falsyCustomAttributes = [];
-		Object.entries( customAttrs ).forEach( entriesPair => {
-			if ( entriesPair[ 1 ] ) {
-				truthyCustomAttributes.push( entriesPair[ 0 ] );
+
+		for ( const name in customAttrs ) {
+			if ( customAttrs[ name ] ) {
+				truthyCustomAttributes.push( name );
 			} else {
-				falsyCustomAttributes.push( entriesPair[ 0 ] );
+				falsyCustomAttributes.push( name );
 			}
-		} );
+		}
 
 		model.change( writer => {
 			// If selection is collapsed then update selected link or insert new one at the place of caret.

+ 6 - 6
packages/ckeditor5-link/src/linkediting.js

@@ -18,8 +18,9 @@ import findLinkRange from './findlinkrange';
 import '../theme/link.css';
 
 const HIGHLIGHT_CLASS = 'ck-link_selected';
-const AUTO = 'automatic';
-const MANUAL = 'manual';
+const DECORATOR_AUTOMATIC = 'automatic';
+const DECORATOR_MANUAL = 'manual';
+const EXTERNAL_LINKS_REGEXP = /^(https?:)?\/\//;
 
 /**
  * The link engine feature.
@@ -78,8 +79,8 @@ export default class LinkEditing extends Plugin {
 
 		const linkDecorators = editor.config.get( 'link.decorators' ) || [];
 
-		this.enableAutomaticDecorators( linkDecorators.filter( item => item.mode === AUTO ) );
-		this.enableManualDecorators( linkDecorators.filter( item => item.mode === MANUAL ) );
+		this.enableAutomaticDecorators( linkDecorators.filter( item => item.mode === DECORATOR_AUTOMATIC ) );
+		this.enableManualDecorators( linkDecorators.filter( item => item.mode === DECORATOR_MANUAL ) );
 
 		// Enable two-step caret movement for `linkHref` attribute.
 		bindTwoStepCaretToAttribute( editor.editing.view, editor.model, this, 'linkHref' );
@@ -106,9 +107,8 @@ export default class LinkEditing extends Plugin {
 		// Adds default decorator for external links.
 		if ( editor.config.get( 'link.targetDecorator' ) ) {
 			automaticDecorators.add( {
-				mode: AUTO,
+				mode: DECORATOR_AUTOMATIC,
 				callback: url => {
-					const EXTERNAL_LINKS_REGEXP = /^(https?:)?\/\//;
 					return EXTERNAL_LINKS_REGEXP.test( url );
 				},
 				attributes: {