Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed insert table row/column commands when a widget is selected inside the table cell #6752

Merged
merged 2 commits into from
May 7, 2020

Conversation

niegowski
Copy link
Contributor

@niegowski niegowski commented May 6, 2020

Suggested merge commit message (convention)

Fix (table): Fixed insert table row/column commands when a widget is selected inside the table cell. Closes #6607.


Additional information

@niegowski niegowski requested a review from jodator May 6, 2020 18:24
Copy link
Contributor

@jodator jodator left a comment

Choose a reason for hiding this comment

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

I would go with deeper refactor of the commands' execute() methods.

Comment on lines 75 to 84
const referencePosition = insertBefore ? selection.getFirstPosition() : selection.getLastPosition();
const referenceRange = insertBefore ? selection.getFirstRange() : selection.getLastRange();

const tableCell = referenceRange.getContainedElement() || findAncestor( 'tableCell', referencePosition );
const table = tableCell.parent.parent;
const containedElement = referenceRange.getContainedElement();
const isTableCell = containedElement && containedElement.is( 'tableCell' );

const tableCell = isTableCell ? containedElement : findAncestor( 'tableCell', referencePosition );
const table = findAncestor( 'table', tableCell );

const { column } = tableUtils.getCellLocation( tableCell );
Copy link
Contributor

Choose a reason for hiding this comment

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

I would change the whole thing to:

		const affectedTableCells = getSelectionAffectedTableCells( selection );
		const columnIndexes = getColumnIndexes( affectedTableCells );

		const column = insertBefore ? columnIndexes.first : columnIndexes.last;
		const table = findAncestor( 'table', affectedTableCells[ 0 ] );

if the tests aren't too simplistic it works 🤷‍♂️.

AFAICS the same thing can be done with inserting rows.

Copy link
Contributor

Choose a reason for hiding this comment

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

The reason I would see that change is that it looks like this code tried to copy utility methods behavior that we already have. Using utility method for extracting this data makes me safe that we do it properly.

@niegowski niegowski requested a review from jodator May 7, 2020 08:49
@jodator jodator merged commit 3d85aca into master May 7, 2020
@jodator jodator deleted the i/6607 branch May 7, 2020 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Editor crashes when pressing tab in a table cell with selection on an image
2 participants