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

Paste Extension: keyboard shortcut paste not triggering editablePaste with event #1573

Open
marcelotedeschi opened this issue Apr 9, 2021 · 1 comment

Comments

@marcelotedeschi
Copy link

Description

Hi! Thanks a lot for the add-on, it's awesome :)

I'm currently having the following issue:
When trying to paste using cmd + v on the contenteditable, the editablePaste event triggered does not contain the original event information. Instead, the editable element is returned three times:

this.trigger('editablePaste', { currentTarget: editable, target: editable }, editable);

From what I understand, this is manually triggered because the paste event happens inside of the pastebin.

Originally changed here:
#1099
and fixed, partially, here:
#1124

I understand the reason behind it, but I don't know why returning the same object three times is necessary, specially without sending the original event !

My use case is I want to allow pasting files, which I need to do after the past extension does its thing and triggers the editablePaste event. But without the original event information, it's impossible. Unless I'm missing something !

I appreciate the support and I can offer to create a PR if that helps :)

Steps to reproduce

  1. Paste using keyboard commands (cmd + v)
  2. Subscribe to editablePaste event trigger

Expected behavior:
Receive the original paste event as a parameter

Actual behavior:
A "fake" event object containing two times the same object is returned

Versions

  • medium-editor: 5.23.3
  • browser: Chrome v89
  • OS: Mac OS 10.15
@andrewevans
Copy link

I found a workaround that is caused by (I think?) the pasting action going in to the hidden Medium Editor <div id="medium-editor-pastebin-1736826967110" style="border: 1px red solid; position: absolute; top: 469.984375px; width: 10px; height: 10px; overflow: hidden; opacity: 0" contenteditable="true">%ME_PASTEBIN%</div> that I destroy on blur. This hack ensures that nothing happens after the ctrl-v paste since I only want to do my work on the actual theElementBeingEdited being blurred.

      let handler;

      theElementBeingEdited.addEventListener('blur', handler = (event) => {
        window.console.info('blur', event.relatedTarget) // <div id="medium-editor-pastebin-1736826967110"...

        if (event.relatedTarget instanceof HTMLElement) return // TODO: Hack to allow ctrl-v paste

        theElementBeingEdited.destroy() // If the editor is not `.destroy()` then the hack is not needed

        // do work
      })

relatedTarget is the element "receiving focus" caused by the blur https://developer.mozilla.org/en-US/docs/Web/API/FocusEvent/relatedTarget .

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

No branches or pull requests

2 participants