Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

I/6502: Refactor TableUtils.removeRows() logic. #303

Merged
merged 23 commits into from
Apr 17, 2020
Merged

I/6502: Refactor TableUtils.removeRows() logic. #303

merged 23 commits into from
Apr 17, 2020

Conversation

jodator
Copy link
Contributor

@jodator jodator commented Apr 10, 2020

Suggested merge commit message (convention)

Fix: Remove row in complex tables now properly move cells from removed rows. Closes ckeditor/ckeditor5#6502.


Additional information

This PR also includes fixes for some issues when not operating on TableEditing model (no post-fixer). ckeditor/ckeditor5#6574.

The actual fix is commented below but to fix that I had to understand the logic once again. Thus refactoring to removing all rows at once (this bring also a benefit of fewer operations when removing more than one row.

As a side effect, I've fixed some of the removeRows() test as it operated on wrongly created table. See: ckeditor/ckeditor5#6574.

previousCell = cellToMove;
} else {
} else if ( !isSpanned ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the line that caused a problem in previous implementation.

@coveralls
Copy link

coveralls commented Apr 10, 2020

Coverage Status

Coverage remained the same at 100.0% when pulling b04996d on i/6502 into 7213f93 on master.

@jodator jodator requested review from niegowski and oleq April 14, 2020 12:53
Copy link
Contributor

@niegowski niegowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments below, also some missing scenario:

Given:

+----+----+----+
| 00 | 01      |
+----+----+----+
| 10 | 11 | 12 |  <-- remove this row
+----+----+----+

Then:

+----+----+----+
| 00 | 01      |
+----+----+----+

Expected:

+----+----+
| 00 | 01 |
+----+----+

src/tableutils.js Outdated Show resolved Hide resolved
if ( headingRows && first < headingRows ) {
const newRows = getNewHeadingRowsValue( first, last, headingRows );
if ( isCellOverlappingRemovedRows ) {
const rowspanAdjustment = lastRowOfCell >= last ? rowsToRemove : first - row;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

first - row is invalid, consider this test scenario:

it( 'should decrease rowspan of table cells from previous rows', () => {
	// +----+----+----+----+
	// | 00 | 01 | 02 | 03 |
	// +----+    +    +    +
	// | 10 |    |    |    |
	// +----+----+    +    +
	// | 20 | 21 |    |    |
	// +----+----+----+    +
	// | 30 | 31 | 32 |    |
	// +----+----+----+----+
	// | 40 | 41 | 42 | 43 |
	// +----+----+----+----+
	setData( model, modelTable( [
		[ '00', { contents: '01', rowspan: 2 }, { contents: '02', rowspan: 3 }, { contents: '03', rowspan: 4 } ],
		[ '10' ],
		[ '20', '21' ],
		[ '30', '31', '32' ],
		[ '40', '41', '42', '43' ]
	] ) );

	tableUtils.removeRows( root.getChild( 0 ), { at: 2, rows: 2 } );

	// +----+----+----+----+
	// | 00 | 01 | 02 | 03 |
	// +----+    +    +    +
	// | 10 |    |    |    |
	// +----+----+----+----+
	// | 40 | 41 | 42 | 43 |
	// +----+----+----+----+
	assertEqualMarkup( getData( model, { withoutSelection: true } ), modelTable( [
		[ '00', { contents: '01', rowspan: 2 }, { contents: '02', rowspan: 2 }, { contents: '03', rowspan: 2 } ],
		[ '10' ],
		[ '40', '41', '42', '43' ]
	] ) );
} );

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You were right. The code wasn't clear enough - even for me.

I've refactored it once again and moved it outside main method execution. Hopefully this is can be parsed a bit better.

As for other cases we will probably see 🤞.

Copy link
Contributor Author

@jodator jodator Apr 15, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change (fix for this issue) is here: c4bfddb.

tests/tableutils.js Outdated Show resolved Hide resolved
tests/tableutils.js Outdated Show resolved Hide resolved
@jodator
Copy link
Contributor Author

jodator commented Apr 15, 2020

Comments below, also some missing scenario:

New/old bug - unrelated to the change. Also a corner case for me and requires much more tests. I'll create a follow up for this issue.

@jodator jodator requested a review from niegowski April 15, 2020 15:59
tests/tableutils.js Show resolved Hide resolved
src/tableutils.js Outdated Show resolved Hide resolved
@jodator
Copy link
Contributor Author

jodator commented Apr 16, 2020

@oleq So the main review is done by @niegowski.

src/tableutils.js Outdated Show resolved Hide resolved
src/tableutils.js Outdated Show resolved Hide resolved
src/tableutils.js Outdated Show resolved Hide resolved
@oleq
Copy link
Member

oleq commented Apr 16, 2020

Can you reproduce this @jodator?

2020-04-16 12 15 58

Copy link
Member

@oleq oleq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only concern as commented: #303 (comment)

@jodator
Copy link
Contributor Author

jodator commented Apr 17, 2020

The only concern as commented: #303 (comment)

@oleq It looks like it is downcast error - I'll handle this in ckeditor/ckeditor5#6437.

@oleq oleq merged commit c8d8d32 into master Apr 17, 2020
@oleq oleq deleted the i/6502 branch April 17, 2020 09:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove row in complex tables sometimes provides invalid results
4 participants