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

Right-Click: Add options to cut/copy/paste blocks #2989

Closed
swissspidy opened this issue Aug 8, 2019 · 8 comments · Fixed by #3083, #3231, #3236 or #3241
Closed

Right-Click: Add options to cut/copy/paste blocks #2989

swissspidy opened this issue Aug 8, 2019 · 8 comments · Fixed by #3083, #3231, #3236 or #3241
Assignees
Labels
Enhancement New feature or improvement of an existing one
Milestone

Comments

@swissspidy
Copy link
Collaborator

As outlined in #2785, let's extend the block settings menu to offer cut + copy options, where the block content is added to the clipboard.

Cases where Gutenberg is adding blocks to the clipboard:

https://github.com/WordPress/gutenberg/blob/b95e865de32ee62d722be3e3e71b334a4b639032/packages/block-editor/src/components/copy-handler/index.js#L26-L57

https://github.com/WordPress/gutenberg/blob/b95e865de32ee62d722be3e3e71b334a4b639032/packages/components/src/clipboard-button/index.js#L27-L67

Pasting would be handled by the RichText component which we use in all the text-based blocks and has some complex logic for handling the clipboard data properly:

https://github.com/WordPress/gutenberg/blob/03121c5e59c63d4c79a293f71bbb7b9613fd311c/packages/rich-text/src/component/index.js#L187-L260

We probably need to copy most of that component's logic.

@swissspidy swissspidy added Enhancement New feature or improvement of an existing one AMP Stories labels Aug 8, 2019
@westonruter
Copy link
Member

Special care will be needed for paste since access is restricted for security/privacy reasons. See https://developers.google.com/web/updates/2018/03/clipboardapi

@spacedmonkey
Copy link
Contributor

Testing details.

User could be able to do the copying.

  1. Copy / cut a block using a keyboard shortcuts crt + c / crt x
  2. Select a block, right click, copy / cut using custom popover menu and not standard OS level context menu.
  3. Blocks can be pasted using keyboard shortcut.
  4. Blocks can be pasted using right context menu.
  5. Block should be able to be pasted multiple times.
  6. When blocks are pasted, they should be pasted where the cursor was placed.
  7. Blocks can be removed using the context menu.
  8. Blocks can be duplicated using the context menu.
  9. Blocks should able to be pasted on another amp page.
  10. Call to action and attachment block, shouldn't be able to copied.

To test this, a test script that mixes and matches elements of this list should be created. An example would be, copy a block using keyboard and paste using the context menu.

@csossi
Copy link

csossi commented Sep 12, 2019

  • "cut" works fine on right-click menu, but the keyboard ctrl-x doesn't remove the original selection (works the same as keyboard ctrl-c)
  • am able to copy CTA blocks

@spacedmonkey
Copy link
Contributor

  • am able to copy CTA blocks

You should be able to copy a CTA block. I can't paste it in the same page, as you can only have one CTA per page. But you can copy and paste a CTA onto another page if you want.

@spacedmonkey
Copy link
Contributor

The cut via keyboard fix has now been merged. See #3231

@csossi
Copy link

csossi commented Sep 13, 2019

Some odd behaviour when ctrl-x/cutting a CTA

  • add a page 2 to a story
  • add a text block
  • add a CTA
  • add a page 3, so you have something like this:
    image
  • ctrl-x on the CTA on page 2
  • ctrl-v on page 3

I ended up with (text got copied over instead):
image

@csossi csossi assigned barklund and unassigned swissspidy Sep 13, 2019
barklund added a commit that referenced this issue Sep 13, 2019
…id bugs

Fixes #2989.

With this change, using the keyboard to cut a block, nothing visually happens, but the selected block is actually copied. Users can still right-click cut the block if they want.

This must be fixed in a future ticket. See inline `todo` for a description of the issue.
@csossi
Copy link

csossi commented Sep 13, 2019

Verified in QA

@spacedmonkey
Copy link
Contributor

Screencast can be found here - https://www.youtube.com/watch?v=47onOiC-EhU&feature=youtu.be

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment