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 mobile paste #1229

Merged
merged 42 commits into from
Feb 7, 2018
Merged

Fix mobile paste #1229

merged 42 commits into from
Feb 7, 2018

Conversation

Comandeer
Copy link
Member

What is the purpose of this pull request?

Bug fix

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

  • Unit tests
  • Manual tests

What changes did you make?

I've added back our beloved paste dialog. It's shown only if user touches the button (via recognising touchend event).

There are missing language files entries that should be added before merging. For now only en locale is covered.

Closes #595.

Copy link
Contributor

@mlewand mlewand left a comment

Choose a reason for hiding this comment

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

Just minor comments, as I had a quick look.

That was a really quick turnaround, nice!

We're missing integration with context menu options.

}

CKEDITOR.tools.array.forEach( editor._.pasteButtons, function( name ) {
var pasteButton = editor.ui.get( name ),
Copy link
Contributor

Choose a reason for hiding this comment

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

This function might return undefined, for instance you could have clipboard plugin, but no "Paste" (or related) button in the toolbar.

Copy link
Member Author

Choose a reason for hiding this comment

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

In such case editor._.pasteButtons should be empty or undefined.

Copy link
Contributor

Choose a reason for hiding this comment

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

@f1ames
Copy link
Contributor

f1ames commented Dec 13, 2017

I extracted context menu integration to #1347.

@f1ames
Copy link
Contributor

f1ames commented Dec 13, 2017

Before merging/closing this ticket #1347 should be covered and merged here.

@mlewand mlewand self-requested a review January 29, 2018 11:02
@mlewand mlewand changed the base branch from master to major February 7, 2018 09:42
@mlewand
Copy link
Contributor

mlewand commented Feb 7, 2018

Rebased onto latest 4.9.0 branch. Changed the base of this PR accordingly.

Copy link
Contributor

@mlewand mlewand left a comment

Choose a reason for hiding this comment

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

I have updated tags in tests, API docs etc. Generally good job, it works reliably.

The good

  • I see that at the same time you took the chance to remove old Opera-related timeouts. Good idea, any setTimeout removed is a win for us, and reduced complexity. 👍

Missed things

  • Change paste dialog message, it says about keyboard. Well it should either about the touch, or just about the native ways to do that.

Notices/discussion

  • Talking about cleanup, this evt.cancel() call doesn't have much sense as the only place firing the pasteDialogCommit event is paste dialog and it doesn't care whether event was canceled or not. WDYT?
  • Doesn't work on Edge/IE11 but it's fine as we do not officially support them. So that's not an issue.

this.customTitle = null;

// Reset commited indicator.
this._.commited = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

commited -> committed

The fix has to be applied across entire PR.

@@ -427,12 +440,19 @@
* an upcoming major release.
*/
editor.getClipboardData = function( callbackOrOptions, callback ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Function signature once again changed, now we're using options once again…

That's a messy situation and we should adjust the API docs correctly. I mean that the options argument is again supported, etc.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've just dropped handling of options as it was used only to set custom title of paste dialog, which wasn't even working.

if ( pasteButton ) {
var buttonElement = CKEDITOR.document.getById( pasteButton._.id );

buttonElement.on( 'touchend', function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking about optimizing this listener, and putting it once on the entire toolbar and just then check what button was pressed. However after playing a bit with it I start to think that it's too much of effort for the benefit. So I guess it's fine the way it is.

}
} );

delete editor._.pasteButtons;
Copy link
Contributor

@mlewand mlewand Feb 7, 2018

Choose a reason for hiding this comment

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

Let's not remove this member from the editor, so it could be reused by other plugins if needed this workarounds for mobile.

* Internal event to open the Paste dialog window.
*
* @private
* @event pasteDialog
Copy link
Contributor

Choose a reason for hiding this comment

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

We should note that pasteDialog event was not available in 4.7.0 - 4.8.0 versions.

* @param {String} name Name of the button.
* @param {Object} definition Definition of the button.
*/
addPasteButton: function( editor, name, definition ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

addPasteButton should return created CKEDITOR.ui.button instance, so that we could use it for instance with Balloon Toolbar.

Copy link
Member Author

Choose a reason for hiding this comment

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

Due to the super convoluted way of accessing button instance from our UI, we decided to not introduce this change. Info gathered from editor._.pasteButtons should be enough to create buttons for Balloon Toolbar.

@Comandeer
Copy link
Member Author

Talking about cleanup, this evt.cancel() call doesn't have much sense as the only place firing the pasteDialogCommit event is paste dialog and it doesn't care whether event was canceled or not. WDYT?

It was a part of whole dialog logic from the beginning and revert of dialog deletion brought it back. Honestly I also don't see much sense in it, but I was just afraid to touch it 😄 However it seems that removing it does not change anything.

@Comandeer
Copy link
Member Author

Actually I located the issue: without this evt.cancel, paste event is called twice. So it's better to leave it untouched.

@Comandeer
Copy link
Member Author

I've added unit test for evt.cancel, fixed existing tests and add changelog entry.

@mlewand
Copy link
Contributor

mlewand commented Feb 7, 2018

Thanks for the research. I have rebased onto latest major. There was an issue that on IE unit tests would trigger a security dialog (request for allowing the paste). I have stubbed the document.execCommand for that particular TC and it works OK.

I'll wait with a final R+ for #1347.

@mlewand mlewand self-requested a review February 7, 2018 16:26
Copy link
Contributor

@mlewand mlewand left a comment

Choose a reason for hiding this comment

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

LGTM

Unfortunately, this will reintroduce all the clipboard plugin that we wanted to remove in 4.7.0 - but we can't break pasting on mobiles.

@mlewand mlewand merged commit be89c08 into major Feb 7, 2018
@mlewand mlewand deleted the t/595 branch February 7, 2018 16:27
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.

Fix pasting (paste/paste plain text/paste from word) experience for mobile browsers
3 participants