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

Fix error which appear with columnDelete command when table contained colspans #653

Merged
merged 9 commits into from
Aug 31, 2017

Conversation

msamsel
Copy link
Contributor

@msamsel msamsel commented Jul 17, 2017

What is the purpose of this pull request?

bug fix

Does your PR contain necessary tests?

yes

This PR contains

  • Unit tests
  • Manual tests

What changes did you make?

  • fix bug which forbid to delete columns when those were under colspans.
  • fix bug where only last column was removed when colspan cell was selected.
  • fix bug where cursor position might won't be returned, what generat the console error.
  • add some brackets {} to if statements.

close #577

// Where to put the cursor after columns been deleted?
// 1. Into next cell of the first row if any;
// 2. Into previous cell of the first row if any;
// 3. Into table's parent element;
var cursorPosition = new CKEDITOR.dom.element( firstRowCells[ startColIndex ] || ( startColIndex ? firstRowCells[ startColIndex - 1 ] : table.$.parentNode ) );
var cursorPosition;
if ( map[ 0 ].length - 1 > endColIndex && map[ 0 ][ endColIndex + 1 ].cellIndex !== -1 ) {
Copy link
Member

Choose a reason for hiding this comment

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

Hmm… I don't get the logic behind this condition. It seems to work, but I don't understand why :D Could elaborate?

Copy link
Contributor Author

@msamsel msamsel Jul 24, 2017

Choose a reason for hiding this comment

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

First part of condition map[ 0 ].length - 1 > endColIndex check if there was some columns on the right after deleted part.

  • map[ 0 ].length - 1 is the last index of possible column value
  • endColIndex is last index of deleted column.

Second part of condition map[ 0 ][ endColIndex + 1 ].cellIndex !== -1 checks, if cell (endColIndex + 1) located after deleted column, is still in table. Theoretically it should be always true, if first part is true ;)

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 removed second part it seems to be confusing.

@@ -0,0 +1,74 @@
/* bender-tags: editor,unit */
Copy link
Member

Choose a reason for hiding this comment

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

Tests connected with tableselection plugin should be inserted into tableselection/integrations directory. It allows to easily find all issues related to integrations between tableselection and other plugins.

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'll prepare two sets of test with and without tableselection plugin to cover more cases.

@@ -0,0 +1,14 @@
@bender-tags: 4.7.2, bug, 577
Copy link
Member

Choose a reason for hiding this comment

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

Tests connected with tableselection plugin should be inserted into tableselection/integrations directory. It allows to easily find all issues related to integrations between tableselection and other plugins.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it's done. ;)

1. Open browser console.
1. Select some cells somwhere under merged header.
1. Selection should use `tableselection` plugin.
1. Right click to open cntentxt menu.
Copy link
Member

Choose a reason for hiding this comment

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

Please fix typos in test description.

this.doTest( 'table-1', 'columnDelete' );
},

'test remove 2 last columns by single row selection': function() {
Copy link
Member

Choose a reason for hiding this comment

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

Please add ticket references before every test connected with it.

// Where to put the cursor after columns been deleted?
// 1. Into next cell of the first row if any;
// 2. Into previous cell of the first row if any;
// 3. Into table's parent element;
var cursorPosition = new CKEDITOR.dom.element( firstRowCells[ startColIndex ] || ( startColIndex ? firstRowCells[ startColIndex - 1 ] : table.$.parentNode ) );
var cursorPosition;
Copy link
Member

Choose a reason for hiding this comment

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

Actually I wonder if it could be moved to tableselection plugin using its internal customizeTableCommand function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Generally tabletools doesn't depend on tableselection so we cannot assume that tableselection will be loaded.

@msamsel msamsel force-pushed the t/577 branch 2 times, most recently from d29de25 to 7e9cd3a Compare July 24, 2017 13:14
@Comandeer Comandeer self-requested a review August 1, 2017 12:26
Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

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

Fix is not working properly

Case 1

  1. Open http://tests.ckeditor.dev:1030/tests/plugins/tableselection/manual/integrations/tabletools/columndeletionerror
  2. Select cells from two last columns.
  3. Open context menu and select Column → Delete Columns.
  4. Press Undo.
  5. Click into cell in the last column (selection should become collapsed).
  6. Open context menu and select Column → Delete Columns.

Expected:

Last column is deleted.

Actual:

Nothing happens.

Case 2

  1. Open http://tests.ckeditor.dev:1030/tests/plugins/tabletools/manual/columndeletionerror
  2. Select cells from two last columns (actually it's equivalent to select some rows).
  3. Click inside cell in last column to collapse selection.
  4. Open context menu and select Column → Delete columns.

Expected:

Last column is deleted.

Actual:

Nothing happens.

@msamsel
Copy link
Contributor Author

msamsel commented Aug 3, 2017

@Comandeer
It's actually browser problem. I've report it to them:

Browser natively, after opening context menu, highlight clicked word. In this case it cause enlarging selection to next cell if we're at the end of cell.

Do you think that I should prepare some custom solution to fix in CKEditor?

@Comandeer
Copy link
Member

There are already some workarounds for context menu in our tableselection plugin, so it won't be any extraordinary situation. Such temporary workaround could be deleted when upstream issues will be fixed.

}

// Problem occures only on webkit in case of native selection (#577
if ( CKEDITOR.env.webkit && !selection.isFake && selection.getNative().type === 'Range' ) {
Copy link
Member

Choose a reason for hiding this comment

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

Is the last part of the statement really needed? Probably it could be replaced with checking if range is non-collapsed.

return range.select();
}

// Problem occures only on webkit in case of native selection (#577
Copy link
Member

Choose a reason for hiding this comment

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

It'll be nice to link also upstream issue here.

1. Select some cells somewhere under merged header.
1. Selection should use native selection.
1. Right click to open context menu.
1. Select Column -> Delete Column.
Copy link
Member

Choose a reason for hiding this comment

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

It's "Delete Columns", not "Column".

Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

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

I've found one more issue with fix for Chrome.

  1. Put collapsed selection on the end of cell in column 4.
  2. Press right mouse button and select "Column"→"Delete Columns"
  3. Press "Undo" button

Expected result: selection is contained inside one cell.

Actual result: two cells are selected: the desired one and the first one from the next row.

@msamsel
Copy link
Contributor Author

msamsel commented Aug 30, 2017

@Comandeer mentioned behaviour seems to be not related to this bug.

  • You can reproduce your steps but instead of right-click use shortcut to open context menu Shift + F10. You will see that applying undo after that will restore proper collapsed selection.
  • You can modify your steps and after opening context menu close it with ESC button. You will see that selection is extend to both cells even without using column delete.

Entire situation has happens because of using right-click not because of using column delete. And that's why such case should be fixed separately not in a scope of this task.

And task for it, if we decide to make fix for that ;) #846

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.

2 participants