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

Widget has now correct selection behaviour inside tables #1104

Merged
merged 10 commits into from
Nov 27, 2017
Merged

Widget has now correct selection behaviour inside tables #1104

merged 10 commits into from
Nov 27, 2017

Conversation

msamsel
Copy link
Contributor

@msamsel msamsel commented Oct 30, 2017

What is the purpose of this pull request?

Bug fix

Does your PR contain necessary tests?

There is no unit test. Selection use quite unfriendly for testing purposes listener mechanism, which use timeouts to execute.
https://github.com/ckeditor/ckeditor-dev/blob/02c35d9ae44656bd75d0efd69028888195dd2a6f/core/selection.js#L272-L299
I wasn't able to properly repeat the problem. I tried to call just selectionChange event, also fire mouseup, mousedown events with target of different table cell. All those things remain selection on widget even tough problem was fixed already.

This PR contains

  • Unit tests
  • Manual tests

What changes did you make?

  • provide method which return information if element is either widget or widget wrapper.
  • use this method to omit some rules when table selection is checked. As far as I know only tableselection and widget use fake-selection, so this solution should be sufficient for this case

close #1027, close #522

@msamsel msamsel force-pushed the t/1027 branch 2 times, most recently from 4aab72e to 17c72f2 Compare October 30, 2017 13:13
@f1ames f1ames self-requested a review November 3, 2017 11:33
Copy link
Contributor

@f1ames f1ames left a comment

Choose a reason for hiding this comment

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

There is one case in which selection is not visible. When widget in the first table is selected and then text from the second table gets selected:

nov-03-2017 14-24-55

The selection is not visible, however it is there, because typing works fine (from what I see it happens only for non-collapsed selection).


Dragging widgets also looks a little strange. The widget is dragged properly and placed in the proper cell (you can compare how it behaves in widgetintable and widgetintablewithtableselection tests), however due to a fact that custom table selection gets activated it looks strange (not sure if it is related to this fix, if not it should be extracted to separate issue):

nov-03-2017 14-40-39


Maybe you could add manual test covering #1027 scenario (you may put it
in tests/tickets/ directory)?

Also when writing test scenario, remember to put dots after each step (if it's a sentence):

1. Click into widgets in table.
1. Try to select some text **in table**.

*
* @since 4.8.0
* @static
* @param {CKEDItOR.dom.element} node
Copy link
Contributor

Choose a reason for hiding this comment

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

As CKEDITOR.dom.element inherits from CKEDITOR.dom.node and this method accepts both, shouldn't this param be {CKEDITOR.dom.node} node ?

Also there is a typo:

CKEDItOR

* @param {CKEDItOR.dom.element} node
* @returns {Boolean}
*/
Widget.isDomWidget = function( node ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Took me some time to understand why those methods are named like that (with the Dom part). It checks if given node is a widget element for CKEDITOR.dom.* representation. The other ones are with Parser (e.g. isParserWidgetElement) related to CKEDITOR.htmlParser.* namespace, makes sense 👍

@@ -96,6 +98,11 @@
return table.equals( fakeTable ) || fakeTable.contains( table );
}

// When widget is selected, then definately is not a table.
Copy link
Contributor

Choose a reason for hiding this comment

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

Issue number could be added here.

@@ -19,7 +19,9 @@
if ( ranges.length === 0 ) {
return false;
}

if ( CKEDITOR.plugins.widget && CKEDITOR.plugins.widget.isDomWidget( ranges[ 0 ].getEnclosedNode() ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Issue number could be added here (with some short comment maybe?).

@@ -269,15 +270,19 @@
if ( !evt.data.getTarget().getName ) {
return;
}
// Prevent of applying table selection when widget is selected.
// Mouseup remain possibility to finish table selection when user release mouse button above widget in table.
if ( evt.name !== 'mouseup' && CKEDITOR.plugins.widget && CKEDITOR.plugins.widget.isDomWidget( evt.data.getTarget() ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This line introduced one unexpected (I think), behaviour:

Before:
nov-03-2017 14-11-53

After:
nov-03-2017 14-11-35

so when dragging mouse over widgets, cells are not selected with fake selection as they would normally be.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Extracted to #1125

}
} );

CKEDITOR.plugins.add( 'blockWidget', {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe you could extract those widget definitions to some helper as they are duplicated in both manual tests?


----

1. Click into widgets in table
Copy link
Contributor

Choose a reason for hiding this comment

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

Click on the widget in table

1. Click into widgets in table
1. Try to select some text **in table**
1. Perform some operation on selected text ( change, append new text, apply some style, etc. )
1. Check behaviour inside inner and outer table depend of testing widget
Copy link
Contributor

Choose a reason for hiding this comment

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

This step is a little unclear. I assume it means to test for both text in nested and outer table. Maybe it can be skipped and added to the instructions below test scenario?


_Perform above steps for all widgets and both editors._

**Expected:** Widget is deselect when focus is changed to text in table. You are able to perfom operatons on selected text.
Copy link
Contributor

Choose a reason for hiding this comment

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

Widget is deselect when focus is changed to text in table and text selection is visible. You are...

1. Try to select some text **in table**
1. Perform some operation on selected text ( change, append new text, apply some style, etc. )
1. Check behaviour inside inner and outer table depend of testing widget
1. Try to add new widget in table ( buttons without icon in toolbr )
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks a little out of place here. We can treat it as a last step of the scenario, but then it misses expected result. You can:

  • Extract it as a second test scenario (well, pretty short one).
  • Rearrange scenario in a way that the user/tester should add a widget on the beginning and then proceed with the rest of the steps (so added widget will also be a part of further testing).

@f1ames
Copy link
Contributor

f1ames commented Nov 3, 2017

I see the case with widget drag&drop is reported in #710 (Case 1), the question is if the cause is the same so it can also be solved by this fix?

@msamsel
Copy link
Contributor Author

msamsel commented Nov 6, 2017

First case with missing selection. Problem it's not related to this case and might be reproduced without widget. More details here: #1122

Dragging problems (Activation table selection, and problem with dropping to proper cell) are covered by #710 (case 1 and 2)

Problem with not having tableselection when going with cursor above the widgets is reported here: #1125

@msamsel msamsel force-pushed the t/1027 branch 2 times, most recently from 00a2cf2 to fdb4ffe Compare November 6, 2017 14:57
@msamsel msamsel requested a review from f1ames November 6, 2017 15:04
Copy link
Contributor

@f1ames f1ames left a comment

Choose a reason for hiding this comment

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

Nice work with extracting all the issues 👍

Just some small corrections in tests needed.

@@ -1,17 +1,17 @@
@bender-tags: 1027, 4.8.0, widget
@bender-ui: collapsed
@bender-ckeditor-plugins: undo,clipboard,basicstyles,toolbar,wysiwygarea,widget,table,resize,tableselection
@bender-include: ../_helpers/testwidgets.js
@bender-ckeditor-plugins: undo,clipboard,basicstyles,toolbar,wysiwygarea,widget,table,resize
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing tableresize plugin here.

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 assume you have tableselection on your mind ;)
I've copy paste the description earlier and haven't notice that is missing now :(

@@ -0,0 +1,27 @@
<textarea id="editor">
<p>Lena's path: "../../_assets/lena.jpg"</p>
Copy link
Contributor

Choose a reason for hiding this comment

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

I suggest moving this path to test description (.md file) when you open the dialog you are unable to select and copy the path and I believe this is the main case here ;)

Copy link
Contributor

Choose a reason for hiding this comment

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

You may put it inside input so it will be easy to copy in IEs.

@@ -0,0 +1,17 @@
@bender-tags: 1027, 4.8.0, widget
Copy link
Contributor

Choose a reason for hiding this comment

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

This test could be ignored for IE8-10 as tableselection is not supported there so it will be exactly the same as .../manual/widgetintable test.

@@ -0,0 +1,15 @@
@bender-tags: 1027, 4.8.0, widget
Copy link
Contributor

Choose a reason for hiding this comment

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

This test could be ignored for IE8-10 as tableselection is not supported there.

@mlewand
Copy link
Contributor

mlewand commented Nov 8, 2017

Gents, just one thing - I'd like to have @Comandeer a second look at it before it gets merged just for extra safety. So @Comandeer please give it a look once it gets a final R+ (I'll mark you already).

Copy link
Contributor

@f1ames f1ames left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@f1ames
Copy link
Contributor

f1ames commented Nov 21, 2017

You may now take a look @Comandeer.

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.

Overall seems very solid and well, I have only some stylistic objections.

@@ -96,6 +99,11 @@
return table.equals( fakeTable ) || fakeTable.contains( table );
}

// When widget is selected, then definately is not a table (#1027).
Copy link
Member

Choose a reason for hiding this comment

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

Typo: "definitely".

@@ -208,7 +208,8 @@
// The selection is inside one cell, so we should allow native selection,
// but only in case if no other cell between mousedown and mouseup
// was selected.
if ( !fakeSelection.dirty && cells.length === 1 ) {
// We don't want to clear selection if widget is event target (#1027).
if ( !fakeSelection.dirty && cells.length === 1 && !( CKEDITOR.plugins.widget && CKEDITOR.plugins.widget.isDomWidget( evt.data.getTarget() ) ) ) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we could extract the second part to some function as it's repeated several times in the code?

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 repeated both here and in core/selection.js.

@@ -0,0 +1,34 @@
<label>Lena's path: <input style="border:2px solid black" type="text" value="../../_assets/lena.jpg" readonly></label>
Copy link
Member

Choose a reason for hiding this comment

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

I'l move this test to plugins/tableselection/integrations directory

CKEDITOR.replace( 'divarea', {
removePlugins: 'tableselection',
extraPlugins: 'divarea,inlineWidget,blockWidget'
} )
Copy link
Member

Choose a reason for hiding this comment

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

Missing semicolon.


CKEDITOR.replace( 'divarea', {
extraPlugins: 'divarea,inlineWidget,blockWidget'
} )
Copy link
Member

Choose a reason for hiding this comment

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

Missing semicolon.

@@ -226,6 +234,7 @@
realSel = this.getSelection( 1 );
// If real (not locked/stored) selection was moved from hidden container
// or is not a table one, then the fake-selection must be invalidated.

Copy link
Member

Choose a reason for hiding this comment

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

Seems like unnecessary blank line.

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 found one more issue in IE8:

  1. Open http://tests.ckeditor.test:1030/tests/plugins/widget/integration/table/manual/widgetintable
  2. In the first row of the first table in the first editor place cursors after the widget (you'll probably have to focus the widget and press right arrow).
  3. Try to add new widget.

Expected
New widget is inserted after the existing one.

Actual
Existing widget gets focus or is replaced by the new widget.

@@ -11,6 +11,10 @@
fillingCharSequenceRegExp = new RegExp( fillingCharSequence + '( )?', 'g' ),
isSelectingTable;

function _isWidget( element ) {
Copy link
Member

Choose a reason for hiding this comment

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

Actually there isn't a need to prefix such function with _ as it's not a method. isWidget would be enough.

@@ -16,6 +16,10 @@
insertRow,
insertColumn;

function _isWidget( element ) {
Copy link
Member

Choose a reason for hiding this comment

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

Actually there isn't a need to prefix such function with _ as it's not a method. isWidget would be enough.

@msamsel
Copy link
Contributor Author

msamsel commented Nov 24, 2017

I've extracted IE8 issue to separate task #1226. It existed before my change.

@msamsel msamsel requested a review from Comandeer November 24, 2017 16:01
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.

LGTM! @f1ames, please, do the honors ;)

@f1ames f1ames merged commit be26f77 into major Nov 27, 2017
@f1ames f1ames deleted the t/1027 branch November 27, 2017 12:57
@Yanual
Copy link

Yanual commented Dec 28, 2017

I just downloaded the tableselection plugin on version 4.8 and got an error: "plugin.js: 20 Uncaught TypeError: CKEDITOR.plugins.widget.isDomWidget is not a function", I look at the functions available in the plugin widget and i try the isDomWidgetElement function and the error does not happen again. I would like to know if my modification is correct and why I have had this problem (am I the only one?) or if there is another sollution ?

@mlewand
Copy link
Contributor

mlewand commented Dec 28, 2017

@Yanual please report this case as a separate issue, according to our issue template (with step-by-step reproduction instruction).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants