Browse Source

Code style: Switched to ESLint.

Kamil Piechaczek 8 years ago
parent
commit
5edc6ef104

+ 8 - 8
packages/ckeditor5-undo/src/basecommand.js

@@ -87,7 +87,7 @@ export default class BaseCommand extends Command {
 		const selectionRanges = [];
 
 		// Transform all ranges from the restored selection.
-		for ( let range of ranges ) {
+		for ( const range of ranges ) {
 			const transformedRanges = transformSelectionRange( range, deltas );
 
 			// For each `range` from `ranges`, we take only one transformed range.
@@ -95,7 +95,7 @@ export default class BaseCommand extends Command {
 			// got transformed to multi-range selection. We will take the first range that
 			// is not in the graveyard.
 			const transformedRange = transformedRanges.find(
-				( range ) => range.start.root != document.graveyard
+				range => range.start.root != document.graveyard
 			);
 
 			// `transformedRange` might be `undefined` if transformed range ended up in graveyard.
@@ -117,7 +117,7 @@ function transformSelectionRange( range, deltas ) {
 	// The range will be transformed by history deltas that happened after the selection got stored.
 	// Note, that at this point, the document history is already updated by undo command execution. We will
 	// not transform the range by deltas that got undone or their reversing counterparts.
-	let transformed = transformRangesByDeltas( [ range ], deltas );
+	const transformed = transformRangesByDeltas( [ range ], deltas );
 
 	// After `range` got transformed, we have an array of ranges. Some of those
 	// ranges may be "touching" -- they can be next to each other and could be merged.
@@ -125,9 +125,9 @@ function transformSelectionRange( range, deltas ) {
 	transformed.sort( ( a, b ) => a.start.isBefore( b.start ) ? -1 : 1 );
 
 	// Then, we check if two consecutive ranges are touching.
-	for ( let i = 1 ; i < transformed.length; i++ ) {
-		let a = transformed[ i - 1 ];
-		let b = transformed[ i ];
+	for ( let i = 1; i < transformed.length; i++ ) {
+		const a = transformed[ i - 1 ];
+		const b = transformed[ i ];
 
 		if ( a.end.isTouching( b.start ) ) {
 			a.end = b.end;
@@ -141,8 +141,8 @@ function transformSelectionRange( range, deltas ) {
 
 // Transforms given set of `ranges` by given set of `deltas`. Returns transformed `ranges`.
 export function transformRangesByDeltas( ranges, deltas ) {
-	for ( let delta of deltas ) {
-		for ( let operation of delta.operations ) {
+	for ( const delta of deltas ) {
+		for ( const operation of delta.operations ) {
 			// We look through all operations from all deltas.
 
 			for ( let i = 0; i < ranges.length; i++ ) {

+ 5 - 5
packages/ckeditor5-undo/src/redocommand.js

@@ -43,7 +43,7 @@ export default class RedoCommand extends BaseCommand {
 			// that happened after the selection state got saved. Unfortunately it is tricky, because those deltas
 			// are already compressed in the history (they are removed).
 			// Because of that we will transform the selection only by non-redo deltas
-			const deltas = Array.from( this.editor.document.history.getDeltas( nextBaseVersion ) ).filter( ( delta ) => {
+			const deltas = Array.from( this.editor.document.history.getDeltas( nextBaseVersion ) ).filter( delta => {
 				return !this._createdBatches.has( delta.batch );
 			} );
 
@@ -73,7 +73,7 @@ export default class RedoCommand extends BaseCommand {
 
 		// We will process each delta from `storedBatch`, in reverse order. If there was deltas A, B and C in stored batch,
 		// we need to revert them in reverse order, so first reverse C, then B, then A.
-		for ( let deltaToRedo of deltasToRedo ) {
+		for ( const deltaToRedo of deltasToRedo ) {
 			// Keep in mind that all algorithms return arrays. That's because the transformation might result in multiple
 			// deltas, so we need arrays to handle them anyway. To simplify algorithms, it is better to always have arrays
 			// in mind. For simplicity reasons, we will use singular form in descriptions and names.
@@ -86,14 +86,14 @@ export default class RedoCommand extends BaseCommand {
 			// 1. Transform that delta by deltas from history that happened after it.
 			// Omit deltas from "redo" batches, because reversed delta already bases on them. Transforming by them
 			// again will result in incorrect deltas.
-			for ( let historyDelta of document.history.getDeltas( nextBaseVersion ) ) {
+			for ( const historyDelta of document.history.getDeltas( nextBaseVersion ) ) {
 				if ( !this._createdBatches.has( historyDelta.batch ) ) {
 					reversedDelta = deltaTransform.transformDeltaSets( reversedDelta, [ historyDelta ], true ).deltasA;
 				}
 			}
 
 			// 2. After reversed delta has been transformed by all history deltas, apply it.
-			for ( let delta of reversedDelta ) {
+			for ( const delta of reversedDelta ) {
 				// Fix base version.
 				delta.baseVersion = document.version;
 
@@ -101,7 +101,7 @@ export default class RedoCommand extends BaseCommand {
 				redoingBatch.addDelta( delta );
 
 				// Now, apply all operations of the delta.
-				for ( let operation of delta.operations ) {
+				for ( const operation of delta.operations ) {
 					document.applyOperation( operation );
 				}
 			}

+ 2 - 2
packages/ckeditor5-undo/src/undo.js

@@ -170,11 +170,11 @@ export default class Undo extends Plugin {
 		const editor = this.editor;
 		const command = editor.commands.get( name );
 
-		editor.ui.componentFactory.add( name, ( locale ) => {
+		editor.ui.componentFactory.add( name, locale => {
 			const view = new ButtonView( locale );
 
 			view.set( {
-				label: label,
+				label,
 				icon: Icon,
 				keystroke,
 				tooltip: true

+ 14 - 12
packages/ckeditor5-undo/src/undocommand.js

@@ -7,8 +7,7 @@
  * @module undo/undocommand
  */
 
-import BaseCommand from './basecommand';
-import { transformRangesByDeltas } from './basecommand';
+import { default as BaseCommand, transformRangesByDeltas } from './basecommand';
 import deltaTransform from '@ckeditor/ckeditor5-engine/src/model/delta/transform';
 
 /**
@@ -33,7 +32,7 @@ export default class UndoCommand extends BaseCommand {
 	 */
 	_doExecute( batch = null ) {
 		// If batch is not given, set `batchIndex` to the last index in command stack.
-		let batchIndex = batch ? this._stack.findIndex( ( a ) => a.batch == batch ) : this._stack.length - 1;
+		const batchIndex = batch ? this._stack.findIndex( a => a.batch == batch ) : this._stack.length - 1;
 
 		const item = this._stack.splice( batchIndex, 1 )[ 0 ];
 
@@ -89,7 +88,7 @@ export default class UndoCommand extends BaseCommand {
 
 		// We will process each delta from `batchToUndo`, in reverse order. If there was deltas A, B and C in undone batch,
 		// we need to revert them in reverse order, so first reverse C, then B, then A.
-		for ( let deltaToUndo of deltasToUndo ) {
+		for ( const deltaToUndo of deltasToUndo ) {
 			// Keep in mind that all algorithms return arrays. That's because the transformation might result in multiple
 			// deltas, so we need arrays to handle them anyway. To simplify algorithms, it is better to always have arrays
 			// in mind. For simplicity reasons, we will use singular form in descriptions and names.
@@ -111,7 +110,7 @@ export default class UndoCommand extends BaseCommand {
 			updatedDeltaToUndo.reverse();
 			let reversedDelta = [];
 
-			for ( let delta of updatedDeltaToUndo ) {
+			for ( const delta of updatedDeltaToUndo ) {
 				reversedDelta.push( delta.getReversed() );
 			}
 
@@ -121,7 +120,7 @@ export default class UndoCommand extends BaseCommand {
 			// 3. Transform reversed delta by history deltas that happened after delta to undo. We have to bring
 			// reversed delta to the current state of document. While doing this, we will also update history deltas
 			// to the state which "does not remember" delta that we undo.
-			for ( let historyDelta of history.getDeltas( nextBaseVersion ) ) {
+			for ( const historyDelta of history.getDeltas( nextBaseVersion ) ) {
 				// 3.1. Transform selection range stored with history batch by reversed delta.
 				// It is important to keep stored selection ranges updated. As we are removing and updating deltas in the history,
 				// selection ranges would base on outdated history state.
@@ -131,7 +130,9 @@ export default class UndoCommand extends BaseCommand {
 				// This is fine, because we want to transform each selection only once, before transforming reversed delta
 				// by the first delta of the batch connected with the ranges.
 				if ( itemIndex !== null ) {
-					this._stack[ itemIndex ].selection.ranges = transformRangesByDeltas( this._stack[ itemIndex ].selection.ranges, reversedDelta );
+					this._stack[ itemIndex ].selection.ranges = transformRangesByDeltas(
+						this._stack[ itemIndex ].selection.ranges, reversedDelta
+					);
 				}
 
 				// 3.2. Transform reversed delta by history delta and vice-versa.
@@ -145,11 +146,12 @@ export default class UndoCommand extends BaseCommand {
 					updatedHistoryDeltas[ historyDelta.baseVersion ] = [];
 				}
 
-				updatedHistoryDeltas[ historyDelta.baseVersion ] = updatedHistoryDeltas[ historyDelta.baseVersion ].concat( updatedHistoryDelta );
+				const mergedHistoryDeltas = updatedHistoryDeltas[ historyDelta.baseVersion ].concat( updatedHistoryDelta );
+				updatedHistoryDeltas[ historyDelta.baseVersion ] = mergedHistoryDeltas;
 			}
 
 			// 4. After reversed delta has been transformed by all history deltas, apply it.
-			for ( let delta of reversedDelta ) {
+			for ( const delta of reversedDelta ) {
 				// Fix base version.
 				delta.baseVersion = document.version;
 
@@ -157,7 +159,7 @@ export default class UndoCommand extends BaseCommand {
 				undoingBatch.addDelta( delta );
 
 				// Now, apply all operations of the delta.
-				for ( let operation of delta.operations ) {
+				for ( const operation of delta.operations ) {
 					document.applyOperation( operation );
 				}
 			}
@@ -168,12 +170,12 @@ export default class UndoCommand extends BaseCommand {
 			// And all deltas that are reversing it.
 			// So the history looks like both original and reversing deltas never happened.
 			// That's why we have to update history deltas - some of them might have been basing on deltas that we are now removing.
-			for ( let delta of reversedDelta ) {
+			for ( const delta of reversedDelta ) {
 				history.removeDelta( delta.baseVersion );
 			}
 
 			// 6. Update history deltas in history.
-			for ( let historyBaseVersion in updatedHistoryDeltas ) {
+			for ( const historyBaseVersion in updatedHistoryDeltas ) {
 				history.updateDelta( Number( historyBaseVersion ), updatedHistoryDeltas[ historyBaseVersion ] );
 			}
 		}

+ 1 - 3
packages/ckeditor5-undo/tests/basecommand.js

@@ -7,15 +7,13 @@ import ModelTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/modeltestedit
 import BaseCommand from '../src/basecommand';
 
 describe( 'BaseCommand', () => {
-	let editor, doc, root, base;
+	let editor, doc, base;
 
 	beforeEach( () => {
 		editor = new ModelTestEditor();
 		base = new BaseCommand( editor );
 
 		doc = editor.document;
-
-		root = doc.getRoot();
 	} );
 
 	afterEach( () => {

+ 4 - 1
packages/ckeditor5-undo/tests/redocommand.js

@@ -32,7 +32,7 @@ describe( 'RedoCommand', () => {
 			const r = ( a, b ) => new Range( p( a ), p( b ) );
 
 			let batch0, batch1, batch2;
-			let batches = new Set();
+			const batches = new Set();
 
 			beforeEach( () => {
 				undo = new UndoCommand( editor );
@@ -53,6 +53,7 @@ describe( 'RedoCommand', () => {
 				batch0 = doc.batch();
 				undo.addBatch( batch0 );
 				batch0.insert( p( 0 ), 'foobar' );
+
 				/*
 				 [root]
 				 - f
@@ -67,6 +68,7 @@ describe( 'RedoCommand', () => {
 				batch1 = doc.batch();
 				undo.addBatch( batch1 );
 				batch1.setAttribute( r( 2, 4 ), 'key', 'value' );
+
 				/*
 				 [root]
 				 - f
@@ -80,6 +82,7 @@ describe( 'RedoCommand', () => {
 				batch2 = doc.batch();
 				undo.addBatch( batch2 );
 				batch2.move( r( 1, 3 ), p( 6 ) );
+
 				/*
 				 [root]
 				 - f

+ 1 - 3
packages/ckeditor5-undo/tests/undo.js

@@ -21,9 +21,7 @@ describe( 'Undo', () => {
 		editorElement = document.createElement( 'div' );
 		document.body.appendChild( editorElement );
 
-		return ClassicTestEditor.create( editorElement, {
-				plugins: [ Undo ]
-			} )
+		return ClassicTestEditor.create( editorElement, { plugins: [ Undo ] } )
 			.then( newEditor => {
 				editor = newEditor;
 			} );

+ 19 - 13
packages/ckeditor5-undo/tests/undocommand.js

@@ -43,6 +43,7 @@ describe( 'UndoCommand', () => {
 				batch0 = doc.batch();
 				undo.addBatch( batch0 );
 				batch0.insert( p( 0 ), 'foobar' );
+
 				/*
 				 [root]
 				 - f
@@ -57,6 +58,7 @@ describe( 'UndoCommand', () => {
 				batch1 = doc.batch();
 				undo.addBatch( batch1 );
 				batch1.setAttribute( r( 2, 4 ), 'key', 'value' );
+
 				/*
 				 [root]
 				 - f
@@ -70,6 +72,7 @@ describe( 'UndoCommand', () => {
 				batch2 = doc.batch();
 				undo.addBatch( batch2 );
 				batch2.move( r( 1, 3 ), p( 6 ) );
+
 				/*
 				 [root]
 				 - f
@@ -83,6 +86,7 @@ describe( 'UndoCommand', () => {
 				batch3 = doc.batch();
 				undo.addBatch( batch3 );
 				batch3.wrap( r( 1, 4 ), 'p' );
+
 				/*
 				 [root]
 				 - f
@@ -95,6 +99,7 @@ describe( 'UndoCommand', () => {
 				 */
 				editor.document.selection.setRanges( [ r( 0, 1 ) ] );
 				batch2.move( r( 0, 1 ), p( 3 ) );
+
 				/*
 				 [root]
 				 - [p]
@@ -239,7 +244,7 @@ describe( 'UndoCommand', () => {
 
 				expect( doc.graveyard.getChild( 0 ).maxOffset ).to.equal( 6 );
 
-				for ( let char of doc.graveyard._children ) {
+				for ( const char of doc.graveyard._children ) {
 					expect( char.hasAttribute( 'key' ) ).to.be.false;
 				}
 
@@ -259,14 +264,15 @@ describe( 'UndoCommand', () => {
 				let text = '';
 
 				for ( let i = 0; i < root.childCount; i++ ) {
-					let node = root.getChild( i );
+					const node = root.getChild( i );
 					text += node.getAttribute( 'uppercase' ) ? node.data.toUpperCase() : node.data;
 				}
 
 				return text;
 			}
 
-			it( 'correctly handles deltas in compressed history that were earlier updated into multiple deltas (or split when undoing)', () => {
+			it( 'correctly handles deltas in compressed history that were earlier updated into multiple deltas ' +
+				'(or split when undoing)', () => {
 				// In this case we assume that one of the deltas in compressed history was updated to two deltas.
 				// This is a tricky edge case because it is almost impossible to come up with convincing scenario that produces it.
 				// At the moment of writing this test and comment, only Undo feature uses `CompressedHistory#updateDelta`.
@@ -280,19 +286,19 @@ describe( 'UndoCommand', () => {
 				expect( getCaseText( root ) ).to.equal( 'abcdef' );
 
 				editor.document.selection.setRanges( [ r( 1, 4 ) ] );
-				let batch0 = doc.batch();
+				const batch0 = doc.batch();
 				undo.addBatch( batch0 );
 				batch0.move( r( 1, 4 ), p( 5 ) );
 				expect( getCaseText( root ) ).to.equal( 'aebcdf' );
 
-				editor.document.selection.setRanges( [ r( 1, 1 ) ]  );
-				let batch1 = doc.batch();
+				editor.document.selection.setRanges( [ r( 1, 1 ) ] );
+				const batch1 = doc.batch();
 				undo.addBatch( batch1 );
 				batch1.remove( r( 0, 1 ) );
 				expect( getCaseText( root ) ).to.equal( 'ebcdf' );
 
 				editor.document.selection.setRanges( [ r( 0, 3 ) ] );
-				let batch2 = doc.batch();
+				const batch2 = doc.batch();
 				undo.addBatch( batch2 );
 				batch2.setAttribute( r( 0, 3 ), 'uppercase', true );
 				expect( getCaseText( root ) ).to.equal( 'EBCdf' );
@@ -301,10 +307,10 @@ describe( 'UndoCommand', () => {
 				expect( getCaseText( root ) ).to.equal( 'BCdEf' );
 
 				// Let's simulate splitting the delta by updating the history by hand.
-				let attrHistoryDelta = doc.history.getDelta( 2 )[ 0 ];
-				let attrDelta1 = new AttributeDelta();
+				const attrHistoryDelta = doc.history.getDelta( 2 )[ 0 ];
+				const attrDelta1 = new AttributeDelta();
 				attrDelta1.addOperation( attrHistoryDelta.operations[ 0 ] );
-				let attrDelta2 = new AttributeDelta();
+				const attrDelta2 = new AttributeDelta();
 				attrDelta2.addOperation( attrHistoryDelta.operations[ 1 ] );
 				doc.history.updateDelta( 2, [ attrDelta1, attrDelta2 ] );
 
@@ -324,13 +330,13 @@ describe( 'UndoCommand', () => {
 				expect( getCaseText( root ) ).to.equal( 'abcdef' );
 
 				editor.document.selection.setRanges( [ r( 1, 4 ) ] );
-				let batch0 = doc.batch();
+				const batch0 = doc.batch();
 				undo.addBatch( batch0 );
 				batch0.setAttribute( r( 1, 4 ), 'uppercase', true );
 				expect( getCaseText( root ) ).to.equal( 'aBCDef' );
 
 				editor.document.selection.setRanges( [ r( 3, 4 ) ] );
-				let batch1 = doc.batch();
+				const batch1 = doc.batch();
 				undo.addBatch( batch1 );
 				batch1.move( r( 3, 4 ), p( 1 ) );
 				expect( getCaseText( root ) ).to.equal( 'aDBCef' );
@@ -349,7 +355,7 @@ describe( 'UndoCommand', () => {
 				expect( getCaseText( root ) ).to.equal( 'abcdef' );
 
 				editor.document.selection.setRanges( [ r( 0, 1 ) ] );
-				let batch0 = doc.batch();
+				const batch0 = doc.batch();
 				undo.addBatch( batch0 );
 				batch0.setAttribute( r( 0, 1 ), 'uppercase', true );
 				expect( getCaseText( root ) ).to.equal( 'Abcdef' );

+ 3 - 5
packages/ckeditor5-undo/tests/undoengine-integration.js

@@ -15,9 +15,7 @@ describe( 'UndoEngine integration', () => {
 	let editor, doc, root;
 
 	beforeEach( () => {
-		return ModelTestEditor.create( {
-				plugins: [ UndoEngine ]
-			} )
+		return ModelTestEditor.create( { plugins: [ UndoEngine ] } )
 			.then( newEditor => {
 				editor = newEditor;
 				doc = editor.document;
@@ -131,7 +129,7 @@ describe( 'UndoEngine integration', () => {
 				output( '<p>fozzz[]o</p><p>bar</p>' );
 
 				setSelection( [ 1, 2 ], [ 1, 2 ] );
-				doc.batch().remove( Range.createFromPositionAndShift( new Position( root, [ 1, 1 ] ) , 1 ) );
+				doc.batch().remove( Range.createFromPositionAndShift( new Position( root, [ 1, 1 ] ), 1 ) );
 				output( '<p>fozzzo</p><p>b[]r</p>' );
 
 				editor.execute( 'undo' );
@@ -149,7 +147,7 @@ describe( 'UndoEngine integration', () => {
 				doc.batch().insert( doc.selection.getFirstPosition(), 'zzz' );
 				output( '<p>fozzz[]o</p><p>bar</p>' );
 
-				doc.batch().remove( Range.createFromPositionAndShift( new Position( root, [ 0, 2 ] ) , 3 ) );
+				doc.batch().remove( Range.createFromPositionAndShift( new Position( root, [ 0, 2 ] ), 3 ) );
 				output( '<p>fo[]o</p><p>bar</p>' );
 
 				editor.execute( 'undo' );