ianstormtaylor / slate

A completely customizable framework for building rich text editors. (Currently in beta.)
http://slatejs.org
MIT License
29.94k stars 3.25k forks source link

can't copy/cut node when select inline-void element alone #4104

Open githoniel opened 3 years ago

githoniel commented 3 years ago

Description can't copy/cut node when select inline-void element alone

Recording just make a inline void element and press ctrl+c, it will not by copyed

Sandbox

https://codesandbox.io/s/slate-reproductions-forked-1omtu?file=/index.js

  1. select image only and ctrl+c, it will not by copyed
  2. select image with text, it will be copyed

Expectation

after investigation, I found that inline void element will rendered with contentEditable={false}

//slate-react
// src/components/element.tsx
if (Editor.isVoid(editor, element)) {
    attributes['data-slate-void'] = true

    if (!readOnly && isInline) {
      attributes.contentEditable = false
    }
}

this will prevent onCopyEvent to trigger

why we need to set `contentEditable = false`  only for inline-void element?

Environment

nivekithan commented 3 years ago

I dont think this is a bug. In this link instead of rendering image I rendered type of element. If you try copying and pasting it you can see that it works as expected.

It works because we are copying and pasting text content so it works but when copying and pasting image we have to explicitly tell how to render these type of content.

For reference you can take a look at source code of image examples

githoniel commented 3 years ago

I dont think this is a bug. In this link instead of rendering image I rendered type of element. If you try copying and pasting it you can see that it works as expected.

It works because we are copying and pasting text content so it works but when copying and pasting image we have to explicitly tell how to render these type of content.

For reference you can take a look at source code of image examples

Image element is block void element in examples while in this issue it is inline void element