Opened 15 years ago
Closed 15 years ago
#4469 closed New Feature (fixed)
Enhance 'Paste As Text'
Reported by: | Garry Yao | Owned by: | Garry Yao |
---|---|---|---|
Priority: | Normal | Milestone: | CKEditor 3.1 |
Component: | Core : Pasting | Version: | |
Keywords: | Confirmed Pasting | Cc: |
Description
Currently 'Paste As Text' will always open dialog for non-IE, we should also try to access native clipboard in other browsers as well, delivering the most satisfied result based on the maximum capability of all browsers.
Change History (6)
comment:1 Changed 15 years ago by
Milestone: | → CKEditor 3.1 |
---|---|
Owner: | set to Garry Yao |
Status: | new → assigned |
Type: | Bug → New Feature |
comment:2 Changed 15 years ago by
Fred's suggested of trying the textarea hack we had used at #1427 to make this happen when user has granted clipboard access, but unfortunately, according to my test, it does't work(the textarea hack is effective only when 'paste' is triggered by a real user action).
comment:3 Changed 15 years ago by
I've been working on this feature in my own editor recently. My conclusions, which I think will help you:
- In Firefox 3+ and using a textarea, the paste event is too late: if you turn off designMode and focus the textarea then nothing gets pasted into it.
- In Firefox 3+ and using a div, the paste event is NOT too late: there's no need to turn off designMode, so just focussing a hidden div in a paste event handler successfully redirects the paste. This is also true in WebKit browsers that support the paste event.
- In Firefox 2+, the textarea trick works if applied in a keypress event handler for Ctrl-V or Shift-Insert, though in Firefox 2 I have found the caret disappears, never to reappear, once you remove the textarea. You can get round this for Firefox 2 by instead redirecting the focus to a textarea in the parent document rather than the editor iframe, though this causes problems in other browsers.
- IE is easy because the textarea and div tricks work if you apply them in a beforepaste event handler.
Conclusions:
- Requiring the user to change any browser settings is bad. This means we can only deal with pastes in code triggered by a real paste action by the user.
- It's clearly better to use the paste or beforepaste events where they exist because that way you detect all pastes, not just those from the keyboard. As I understand it, IE has had paste and beforepaste since version 5, Firefox has had paste only since version 3 and WebKit has had paste only since sometime (not sure when). Opera has neither.
- For rich content (as opposed to plain text), the div trick (redirect the focus to a hidden div in the editor iframe) works fine for all major browsers that support the paste event. Therefore, for rich text pastes you should use the paste event where it exists.
- For plain text content, the textarea trick should be used. Where the beforepaste event exists (IE), the trick should be applied there. Otherwise, the best that can be done is using a keypress event handler and dealing with other pastes some other way (polling the document? Is that how you do it?)
comment:4 Changed 15 years ago by
I've not fully appreciated how beforepaste and paste events work in IE, so you should continue ignoring my previous comment.
comment:5 Changed 15 years ago by
@timdown Your summarization is mostly identical to our discovery, though there were minor divergency here:
- IE is easy because the textarea and div tricks work if you apply them in a beforepaste event handler.
Move IE selection on 'paste' doesn't work, you'll need to paste manually to the temp div with execCommand('paste'), it's the tricky part.
- For plain text content, the textarea trick should be used. Where the beforepaste event exists (IE), the trick should be applied there.
Use exactly the same way as above, only use <textarea> in favor of <div>
So let the codes talk:
comment:6 Changed 15 years ago by
Component: | General → Core : Pasting |
---|---|
Resolution: | → fixed |
Status: | assigned → closed |
The paste branch has been reviewed and merged into 3.1.x branch with [4772].
There's actually a quite old and classic approach which works fine in Firefox(only for text flavor) through the XPCOM clipboard API, I'm porting it here.
Also, the old routine for detecting IE clipboard accessibility could be further simplified.
Those changes are committed with [4303].