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

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
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
Example Codepen
https://codepen.io/natterstefan/pen/PoqLVJr?editors=0110
Research
There is a
enableLineBreakssetting, managing how blocks behave whenenteris pressed. In the example it still looks like this is not working properly.editor.js/src/components/modules/blockEvents.ts
Lines 257 to 263 in be6f9b7
Same goes for
backspace, but here we never reach this part of the code:editor.js/src/components/modules/blockEvents.ts
Lines 353 to 361 in be6f9b7
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
keydownlistener on the document (here)? Because there is anotherbackspacePressedhandler.(Possible) related Issues