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 pasting in Webkit #44

Closed
delambo opened this issue Jan 31, 2013 · 4 comments
Closed

Fix pasting in Webkit #44

delambo opened this issue Jan 31, 2013 · 4 comments

Comments

@delambo
Copy link
Member

delambo commented Jan 31, 2013

Pasting into ice is broken in webkit. This was referenced in #18.

CC @drboone, @johanneswilm

@johanneswilm
Copy link
Contributor

The logic one has to use as far as I know it:
IE/Firefox: one wait for the paste to happen, then cleans up the element, (moves it to the main edit window)
Webkit: one cancels the paste event, copies the clipboard data, cleans it, inserts it

like this:

function handlePaste(e) {
if (e && e.clipboardData && e.clipboardData.getData) { // Webkit: we cancel the paste event, copy clipboard data, clean it, insert it
    e.stopPropagation();
    e.preventDefault();
    if (notRecentlyPasted) {
        notRecentlyPasted = false;
        setTimeout(function () {
            notRecentlyPasted = true;
        }, 1)
        var pasteElement = document.createElement('div');
        if (/text\/html/.test(e.clipboardData.types)) {
            pasteElement.innerHTML = e.clipboardData.getData('text/html');
            removeExtraFormatting(this, pasteElement);

        } else if (/text\/plain/.test(e.clipboardData.types)) {
            pasteElement.innerText = e.clipboardData.getData('text/plain');
        }

        addPasteContents(pasteElement);
        addZombieBR();
        return false;
    }
} else { // IE/Firefox - we wait for the paste to happen, then clean up the entire element
    var oldLength = this.innerHTML.length;
    waitForPaste(this, oldLength);
    return true;
}
}

@delambo Are you working on this right now?

@delambo
Copy link
Member Author

delambo commented Jan 31, 2013

I will work on this sometime in the next couple of weeks. The following is the best cross-browser paste solution that I have tried:

  1. detect ctrl/cmd-v keypress event
  2. set a bookmark in the editor
  3. create a temporary, hidden div element and focus the selection/range into it
  4. set a brief timeout (defer) with a handler that fires after the browser pastes into the div created in (4)
  5. With the handler created in (5), grab the paste from the div, clean it, then insert it into the body at the bookmark

The biggest drawback is that the context/app menu pastes don't work.

@johanneswilm
Copy link
Contributor

I see. Yes, I thought that only works in Firefox/IE, and that in Webkit you need to use the above method. But I may be wrong.

@delambo
Copy link
Member Author

delambo commented Feb 15, 2013

#53 was merged into master

@delambo delambo closed this as completed Feb 15, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants