-
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
Fix for: Pasting inside editor which contains a table after selecting all content is not working #3561
Conversation
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.
Your fix covers only the case where selection boundaries are located directly in the editable. There should be a more generic approach. I'd like to avoid the situation in the near future, where it is necessary to fix a very similar issue, but for content surrounded by div, blockquote, nested in another table, etc.
For example, you can add blockuote
plugin to your manual test and check that fix stops working in such case:
You can also improve code style inside pasteListener
function, as there is already a modification in this part. I would move all helper function to the beginning or to the end of a function scope, so those won't make extra noise during code reading.
I haven't check tests as there is some space for improvement in the proposed fix itself.
Short summary:
I had some major doubts about explicitly naming table elements in this line, but didn't manage to find any existing abstraction for them 🤔 |
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 noticed one bug, however, I see it was also present in 4.12.1.
When you use delete or backspace the content in table cell remains, however when you paste new content, then the entire table cell is cleared out. I couldn't find any similar issue reported.
Maybe you could make short research if this is somehow related to your fix and link it or report as a new issue. I don't want to spend too much time on it as it looks like an edge case.
Correct:
Wrong:
tests/plugins/tableselection/manual/integrations/clipboard/selectall.html
Outdated
Show resolved
Hide resolved
Using |
I had to add one positive early return in |
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 we're closer to the final solution.
Can you also propose the unit tests for cases checked in point 2 and 5? I couldn't find any unit test utilize those and it could be nice to have proper unit tests for them as well.
plugins/tableselection/plugin.js
Outdated
// 2. It's a boundary position but with no table pasted. | ||
isBoundaryWithoutTable = ( boundarySelection && !pastedTable ); | ||
|
||
if ( isBoundaryWithoutTable ) { |
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 are a few places like this one, where are:
- comment describing what is happening
- named variable
It's not always necessary, especially for simple conditions, as it duplicates the same information. I would choose one approach and use it here and in further cases.
Situations like this also tend to desynchronize the code, because the condition might be updated without comment modification or variable name remain the same when conditions are modified and new ones are added.
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.
Well, maybe I indeed created an information overflow here 🤔. As most of the conditions aren't that long, I'd give up creating variables and go with comments before if
s as they have some added value in helping to understand the conditions, while variable names are sometimes unclear.
plugins/tableselection/plugin.js
Outdated
// cell, part of cell etc. | ||
isCollapsedPartial = selectedCells.length === 1 && | ||
!isTableElement && | ||
!boundarySelection; |
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.
!boundarySelection
it seems to be always true
, as all the opposite cases when boundarySelection === true
was already caught in line 884, point 2.1.
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.
However, if you consider my comment to point 2.1, it might be required to remain this check here. It might result that boundarySelection
will be able to have different values 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.
Please check out this comment.
plugins/tableselection/plugin.js
Outdated
// 5. It's single range that does not fully contain table element and is not boundary, e.g. collapsed selection within | ||
// cell, part of cell etc. | ||
isCollapsedPartial = selectedCells.length === 1 && | ||
!isTableElement && |
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.
!isTableElement
will be always false
, because of cases when !isTableElement === true
was already catched in point 3, by earlier if statement.
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.
On one hand it is totally logical, but on the other hand here we explicitly added unrequired parameters to function just to avoid misleading in the future. I'm afraid that if we remove conditions that are unnecessary with current check order above and here, we will lose the information that they are still important and we don't place them just to keep code DRY. We could keep information about omitted conditions in comment, but it won't be save neither as code may desynchronize with comments as you mentioned here. WDYT?
tests/plugins/tableselection/integrations/clipboard/pasteomittingtableselection.js
Outdated
Show resolved
Hide resolved
Added mentioned tests:
|
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.
In the course of changing conditions for |
Co-Authored-By: Mateusz Samsel <[email protected]>
Rebased onto latest |
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, good job @Dumluregn and @msamsel 👍 🎉
What is the purpose of this pull request?
Bugfix
Does your PR contain necessary tests?
All patches which change the editor code must include tests. You can always read more
on PR testing,
how to set the testing environment and
how to create tests
in the official CKEditor documentation.
This PR contains
What is the proposed changelog entry for this pull request?
What changes did you make?
The issue here was caused by the custom
pasteListener()
for table selection plugin. It overrides the default paste logic by moving selection during paste to the first table cell and ignoring the rest of editor:To solve this, I added an extra condition for ignoring this custom pasting.
Closes #875.