-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Conversation
4aab72e
to
17c72f2
Compare
There was a problem hiding this 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:
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):
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**.
plugins/widget/plugin.js
Outdated
* | ||
* @since 4.8.0 | ||
* @static | ||
* @param {CKEDItOR.dom.element} node |
There was a problem hiding this comment.
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
plugins/widget/plugin.js
Outdated
* @param {CKEDItOR.dom.element} node | ||
* @returns {Boolean} | ||
*/ | ||
Widget.isDomWidget = function( node ) { |
There was a problem hiding this comment.
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 👍
core/selection.js
Outdated
@@ -96,6 +98,11 @@ | |||
return table.equals( fakeTable ) || fakeTable.contains( table ); | |||
} | |||
|
|||
// When widget is selected, then definately is not a table. |
There was a problem hiding this comment.
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.
core/selection.js
Outdated
@@ -19,7 +19,9 @@ | |||
if ( ranges.length === 0 ) { | |||
return false; | |||
} | |||
|
|||
if ( CKEDITOR.plugins.widget && CKEDITOR.plugins.widget.isDomWidget( ranges[ 0 ].getEnclosedNode() ) ) { |
There was a problem hiding this comment.
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?).
plugins/tableselection/plugin.js
Outdated
@@ -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() ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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', { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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 ) |
There was a problem hiding this comment.
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).
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? |
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 |
00a2cf2
to
fdb4ffe
Compare
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing tableresize
plugin here.
There was a problem hiding this comment.
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 :(
tests/tickets/1027/1.html
Outdated
@@ -0,0 +1,27 @@ | |||
<textarea id="editor"> | |||
<p>Lena's path: "../../_assets/lena.jpg"</p> |
There was a problem hiding this comment.
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 ;)
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
tests/tickets/1027/1.md
Outdated
@@ -0,0 +1,15 @@ | |||
@bender-tags: 1027, 4.8.0, widget |
There was a problem hiding this comment.
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.
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). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
You may now take a look @Comandeer. |
There was a problem hiding this 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.
core/selection.js
Outdated
@@ -96,6 +99,11 @@ | |||
return table.equals( fakeTable ) || fakeTable.contains( table ); | |||
} | |||
|
|||
// When widget is selected, then definately is not a table (#1027). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: "definitely".
plugins/tableselection/plugin.js
Outdated
@@ -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() ) ) ) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
.
tests/tickets/1027/1.html
Outdated
@@ -0,0 +1,34 @@ | |||
<label>Lena's path: <input style="border:2px solid black" type="text" value="../../_assets/lena.jpg" readonly></label> |
There was a problem hiding this comment.
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' | ||
} ) |
There was a problem hiding this comment.
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' | ||
} ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing semicolon.
core/selection.js
Outdated
@@ -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. | |||
|
There was a problem hiding this comment.
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.
There was a problem hiding this 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:
- Open http://tests.ckeditor.test:1030/tests/plugins/widget/integration/table/manual/widgetintable
- 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).
- 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.
core/selection.js
Outdated
@@ -11,6 +11,10 @@ | |||
fillingCharSequenceRegExp = new RegExp( fillingCharSequence + '( )?', 'g' ), | |||
isSelectingTable; | |||
|
|||
function _isWidget( element ) { |
There was a problem hiding this comment.
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.
plugins/tableselection/plugin.js
Outdated
@@ -16,6 +16,10 @@ | |||
insertRow, | |||
insertColumn; | |||
|
|||
function _isWidget( element ) { |
There was a problem hiding this comment.
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.
I've extracted IE8 issue to separate task #1226. It existed before my change. |
There was a problem hiding this 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 ;)
…vements. Also extracting widget definition in test.
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 ? |
@Yanual please report this case as a separate issue, according to our issue template (with step-by-step reproduction instruction). |
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 firemouseup
,mousedown
events with target of different table cell. All those things remain selection on widget even tough problem was fixed already.This PR contains
What changes did you make?
tableselection
and widget usefake-selection
, so this solution should be sufficient for this caseclose #1027, close #522