codex-team / editor.js

A block-style editor with clean JSON output
https://editorjs.io
Apache License 2.0
28.29k stars 2.06k forks source link

Multiple block selection #2474

Open zeinabzahran opened 1 year ago

zeinabzahran commented 1 year ago

How to select more than one block and perform action like bold or italic to whole selection?

lijie1129 commented 1 year ago

Hi, @zeinabzahran

As of version 2.29.0-rc.0, editor.js still does not support perform inline actions across mutiple blocks.

Ian4869 commented 11 months ago

Hi,Have you found a way to achieve this requirement?

osain-az commented 11 months ago

I can look at it one of these days

anand-cubyts commented 9 months ago

this will be really helpful

sebmeister2077 commented 7 months ago

I've somewhat achieved this by using a MutationObserver on the editor__redactor element, and save which blocks contain the 'selected' class, showing the inline toolbar manually after the mouse up event (adding the necesary classes) and then extending the Inline Tools you need to also handle cross block selections ann apply the styling to all [contenteditable=true] elements

josessolmaximo commented 3 weeks ago

I've somewhat achieved this by using a MutationObserver on the editor__redactor element, and save which blocks contain the 'selected' class, showing the inline toolbar manually after the mouse up event (adding the necesary classes) and then extending the Inline Tools you need to also handle cross block selections ann apply the styling to all [contenteditable=true] elements

how did you show the inline toolbar manually? I tried this.api.inlineToolbar.open() but it doesn't open

sebmeister2077 commented 1 week ago

@josessolmaximo I've added the neccessary classes on the element which are from the editor itself :D, you can check their names by inspecting the toolbar when open.

        document
            .querySelectorAll(".ce-block--selected")
        // css style for visual block selection, other than default because that one is used to determine internal selection state
            .forEach((el) => el.classList.add(this.customCSS.blockSelected));

        // toolbar DOM element
        toolbar.style.left = `max(120px,${toolbar.style.left ?? "0px"})`;
        toolbar.classList.add("ce-inline-toolbar--showed");
justcodej commented 1 week ago

@josessolmaximo我已经在元素上添加了来自编辑器本身的必要类:D,您可以在打开时检查工具栏来检查它们的名称。

        document
            .querySelectorAll(".ce-block--selected")
        // css style for visual block selection, other than default because that one is used to determine internal selection state
            .forEach((el) => el.classList.add(this.customCSS.blockSelected));

        // toolbar DOM element
        toolbar.style.left = `max(120px,${toolbar.style.left ?? "0px"})`;
        toolbar.classList.add("ce-inline-toolbar--showed");

May I ask if you can provide a demonstration or code snippet?

sebmeister2077 commented 6 days ago

@justcodej @josessolmaximo I've uploaded my code here https://github.com/sebmeister2077/editorjs-multiblock-selection-plugin Might publish this on npm but only if i can make this be supported on multiple versions of editorjs..

Currently works on v2.28 for me if you want to check it out