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

Table rows will not be added on tab key press if the associated command is disabled #186

Merged
merged 4 commits into from
May 6, 2019

Conversation

scofalik
Copy link
Contributor

@scofalik scofalik commented May 6, 2019

Suggested merge commit message (convention)

Fix: Table rows will not be added on tab key press if the associated command is disabled. Closes ckeditor/ckeditor5#3268.

@coveralls
Copy link

coveralls commented May 6, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling e6cc3bc on t/185 into 241f067 on master.

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'm not sure about the if in if and what is the case (other then disabled command) of not inserting a row to a table.

@@ -294,6 +294,22 @@ describe( 'TableEditing', () => {
] ) );
} );

it( 'should not create another row and not move the caret if insertTableRowBelow command is disabled', () => {
setModelData( model, modelTable( [
[ '11', '[12]' ]
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe test should include also testing the selection so it should start with collapsed and should stay collapsed (not changed) after the tab.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I copied this from the test above. I can change it to a collapsed selection.

editor.plugins.get( 'TableUtils' ).insertRows( table, { at: table.childCount } );
editor.execute( 'insertTableRowBelow' );

// Re-evaluate `isLastRow`. If `insertTableRowBelow` execution didn't add any row (because it was disabled or it got
Copy link
Contributor

Choose a reason for hiding this comment

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

Too complex? Maybe check if the command is enabled - if not just return.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure what is the case for "got it overwritten in some way" part so maybe I'm wrong here.

But still if the number of rows didn't change I'd exit here rather then in focus condition below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was my first idea, but I wanted to check the content state which is the ultimate source of truth and the indicator of what to do next.

By "got overwritten" I mean that commands behavior (execution) may be overwritten by other features. The command might be enabled but for some reason, it might not add a row. Track changes overwrites commands a lot and some of them do not change the content after execution. I am not yet sure how integration with tables will look like (now you can only add a table but table utils are not supported). So I think I am on a safe side here with the way I coded it.

Copy link
Contributor

Choose a reason for hiding this comment

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

So the part about earlier abort still applies - just return here not below. (number of rows remains the same). WDYT?

Copy link
Contributor Author

@scofalik scofalik May 6, 2019

Choose a reason for hiding this comment

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

But I agree that this is confusing. I am not a big fan of this approach but still, I'd rather be safe than sorry :P.

}

let cellToFocus;

// Move to first cell in next row.
if ( isForward && isLastCellInRow ) {
if ( isLastRow ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't like the if in if here. I'd move that check as if( !command.isEnabled ) { return } to the previous check of inserting table row.

@jodator jodator merged commit 00848a8 into master May 6, 2019
@jodator jodator deleted the t/185 branch May 6, 2019 11:54
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.

Adding a row on tab key should use a command
3 participants