Skip to content

Feature Request (Tool-Setting): add option to not delete selected block on backspace or enter keydown #1090

Description

@natterstefan

Scenario

A block's tool setting opens a modal (or any other new view outside of editorjs). Whenever the user hits backspace or enter in the new view though, the block - which is still selected (.ce-block--selected) - gets deleted.

There is currently no way to remove the selection from the block, when a tune was toggled/clicked.

Example

Screen Capture on 2020-04-01 at 16-40-17

Example Codepen

https://codepen.io/natterstefan/pen/PoqLVJr?editors=0110

Research

There is a enableLineBreaks setting, managing how blocks behave when enter is pressed. In the example it still looks like this is not working properly.

/**
* Don't handle Enter keydowns when Tool sets enableLineBreaks to true.
* Uses for Tools like <code> where line breaks should be handled by default behaviour.
*/
if (tool && tool[Tools.INTERNAL_SETTINGS.IS_ENABLED_LINE_BREAKS]) {
return;
}

Same goes for backspace, but here we never reach this part of the code:

/**
* Don't handle Backspaces when Tool sets enableLineBreaks to true.
* Uses for Tools like <code> where line breaks should be handled by default behaviour.
*
* But if caret is at start of the block, we allow to remove it by backspaces
*/
if (tool && tool[this.Editor.Tools.INTERNAL_SETTINGS.IS_ENABLED_LINE_BREAKS] && !Caret.isAtStart) {
return;
}

Because the block is still selected and results to true in this if.

Feature request

Enable developers to unselect a block when a tune was toggled. Means, a new method is added to the blocks API (https://editorjs.io/api#blocks).

Current Workaround (not 100% tested tough)

When the toggle is clicked, we remove the selected class from the block. This should help us to pass the if`s in the keydown handlers.

But this is kinda hacky IMHO.

Additional questions

(Possible) related Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions