浏览代码

Changed: Refactor TableIterator#iterateOverRow() to TableIterator#iterateOverRows().

Maciej Gołaszewski 7 年之前
父节点
当前提交
62ca8216b1

+ 2 - 2
packages/ckeditor5-table/src/converters/downcasttable.js

@@ -90,7 +90,7 @@ export function downcastInsertRow() {
 
 		const tableIterator = new TableIterator( table );
 
-		for ( const tableCellInfo of tableIterator.iterateOverRow( rowIndex ) ) {
+		for ( const tableCellInfo of tableIterator.iterateOverRows( rowIndex ) ) {
 			const { cell: tableCell, column } = tableCellInfo;
 
 			const trElement = getOrCreateTr( tableRow, rowIndex, tableSection, conversionApi );
@@ -128,7 +128,7 @@ export function downcastInsertCell() {
 
 		const tableIterator = new TableIterator( table );
 
-		for ( const { cell, column } of tableIterator.iterateOverRow( rowIndex ) ) {
+		for ( const { cell, column } of tableIterator.iterateOverRows( rowIndex ) ) {
 			if ( cell === tableCell ) {
 				const cellElementName = getCellElementName( rowIndex, column, headingRows, headingColumns );
 

+ 1 - 1
packages/ckeditor5-table/src/insertrowcommand.js

@@ -60,7 +60,7 @@ export default class InsertRowCommand extends Command {
 
 			let tableCellToInsert = 0;
 
-			for ( const tableCellInfo of tableIterator.iterateOver() ) {
+			for ( const tableCellInfo of tableIterator.iterateOverRows( 0, insertAt + 1 ) ) {
 				const { row, rowspan, colspan, cell } = tableCellInfo;
 
 				if ( row < insertAt ) {

+ 9 - 5
packages/ckeditor5-table/src/tableiterator.js

@@ -53,16 +53,20 @@ export default class TableIterator {
 		}
 	}
 
-	* iterateOverRow( rowIndex ) {
+	* iterateOverRows( fromRow, toRow ) {
+		const startRow = fromRow || 0;
+
+		const endRow = toRow || fromRow;
+
 		for ( const tableCellInfo of this.iterateOver() ) {
 			const { row } = tableCellInfo;
 
-			if ( row === rowIndex ) {
-				yield tableCellInfo;
+			if ( row > endRow ) {
+				return;
 			}
 
-			if ( row > rowIndex ) {
-				return;
+			if ( row >= startRow && row <= endRow ) {
+				yield tableCellInfo;
 			}
 		}
 	}