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

Code style: Fixed some minor code style issues.

Maciej Gołaszewski 7 лет назад
Родитель
Сommit
c6d2e01373

+ 18 - 6
packages/ckeditor5-table/src/commands/setheadercolumncommand.js

@@ -28,9 +28,19 @@ export default class SetHeaderColumnCommand extends Command {
 		const position = selection.getFirstPosition();
 		const tableParent = getParentTable( position );
 
-		this.isEnabled = !!tableParent;
-
-		this.value = this.isEnabled && this._isInHeading( position.parent, tableParent );
+		const isInTable = !!tableParent;
+
+		this.isEnabled = isInTable;
+
+		/**
+		 * Flag indicating whether the command is active. The command is active when the
+		 * {@link module:engine/model/selection~Selection} is in a header column.
+		 *
+		 * @observable
+		 * @readonly
+		 * @member {Boolean} #value
+		 */
+		this.value = isInTable && this._isInHeading( position.parent, tableParent );
 	}
 
 	/**
@@ -49,12 +59,14 @@ export default class SetHeaderColumnCommand extends Command {
 
 		const currentHeadingColumns = parseInt( table.getAttribute( 'headingColumns' ) || 0 );
 
-		const { column } = tableUtils.getCellLocation( tableCell );
+		let { column } = tableUtils.getCellLocation( tableCell );
 
-		const columnsToSet = column + 1 !== currentHeadingColumns ? column + 1 : column;
+		if ( column + 1 !== currentHeadingColumns ) {
+			column++;
+		}
 
 		model.change( writer => {
-			updateNumericAttribute( 'headingColumns', columnsToSet, table, writer, 0 );
+			updateNumericAttribute( 'headingColumns', column, table, writer, 0 );
 		} );
 	}
 

+ 22 - 10
packages/ckeditor5-table/src/commands/setheaderrowcommand.js

@@ -30,9 +30,19 @@ export default class SetHeaderRowCommand extends Command {
 		const position = selection.getFirstPosition();
 		const tableParent = getParentTable( position );
 
-		this.isEnabled = !!tableParent;
-
-		this.value = this.isEnabled && this._isInHeading( position.parent, tableParent );
+		const isInTable = !!tableParent;
+
+		this.isEnabled = isInTable;
+
+		/**
+		 * Flag indicating whether the command is active. The command is active when the
+		 * {@link module:engine/model/selection~Selection} is in a header row.
+		 *
+		 * @observable
+		 * @readonly
+		 * @member {Boolean} #value
+		 */
+		this.value = isInTable && this._isInHeading( position.parent, tableParent );
 	}
 
 	/**
@@ -49,22 +59,24 @@ export default class SetHeaderRowCommand extends Command {
 		const table = tableRow.parent;
 
 		const currentHeadingRows = table.getAttribute( 'headingRows' ) || 0;
-		const rowIndex = tableRow.index;
+		let rowIndex = tableRow.index;
 
-		const rowsToSet = rowIndex + 1 !== currentHeadingRows ? rowIndex + 1 : rowIndex;
+		if ( rowIndex + 1 !== currentHeadingRows ) {
+			rowIndex++;
+		}
 
 		model.change( writer => {
-			if ( rowsToSet ) {
-				// Changing heading rows requires to check if any of a heading cell is overlaping vertically the table head.
+			if ( rowIndex ) {
+				// Changing heading rows requires to check if any of a heading cell is overlapping vertically the table head.
 				// Any table cell that has a rowspan attribute > 1 will not exceed the table head so we need to fix it in rows below.
-				const cellsToSplit = getOverlappingCells( table, rowsToSet, currentHeadingRows );
+				const cellsToSplit = getOverlappingCells( table, rowIndex, currentHeadingRows );
 
 				for ( const cell of cellsToSplit ) {
-					splitHorizontally( cell, rowsToSet, writer );
+					splitHorizontally( cell, rowIndex, writer );
 				}
 			}
 
-			updateNumericAttribute( 'headingRows', rowsToSet, table, writer, 0 );
+			updateNumericAttribute( 'headingRows', rowIndex, table, writer, 0 );
 		} );
 	}
 

+ 2 - 2
packages/ckeditor5-table/src/ui/inserttableview.js

@@ -101,7 +101,7 @@ export default class InsertTableView extends View {
 			// Listen to box view 'over' event which indicates that mouse is over this box.
 			boxView.on( 'over', () => {
 				// Translate box index to the row & column index.
-				const row = parseInt( index / 10 );
+				const row = Math.floor( index / 10 );
 				const column = index % 10;
 
 				// As row & column indexes are zero-based transform it to number of selected rows & columns.
@@ -132,7 +132,7 @@ export default class InsertTableView extends View {
 
 		this.items.map( ( boxView, index ) => {
 			// Translate box index to the row & column index.
-			const itemRow = parseInt( index / 10 );
+			const itemRow = Math.floor( index / 10 );
 			const itemColumn = index % 10;
 
 			// Grid box is highlighted when its row & column index belongs to selected number of rows & columns.