-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Added handling for delete key #1626
Added handling for delete key #1626
Conversation
/** | ||
* Check if Block should be removed by current Delete keydown | ||
*/ | ||
if (currentBlock.selected || (currentBlock.isEmpty && currentBlock.currentInput === currentBlock.firstInput)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The last condition is not clear for me. I suppose there should be currentBlock.lastInput
instead
But I believe such behaviour is not really intuitive, let me explain why.
For example you have list tool, you create couple of lines (but don't type any text there) and press delete key on the last line. You wouldn't expect this will delete the list block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, looks like a bad copy/paste of that line:
if (currentBlock.selected || (currentBlock.isEmpty && currentBlock.currentInput === currentBlock.firstInput)) { |
For example you have list tool, you create couple of lines (but don't type any text there) and press delete key on the last line. You wouldn't expect this will delete the list block
I just copied the behavior of the backspace key. Why would it make sense when pressing backspace and not when pressing delete ? Both have the same semantics for me, only the direction changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it makes sense for paragraph tool, but for more complex tools it looks unintuitive for me. When I press delete I expect next entity to be deleted (or merged with the current one), but not current entity deletion. I might be wrong, so could you please apply changes and I'll take a look in action
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes are already made and rebased.
Being able to delete what has been selected with a rectangular selection is exactly the point of #1315 , and it is working as I would expect.
During my testing, I found a bug on firefox with the current version (on editorjs.io), that somehow disappeared with my version. When pressing delete on an empty list item, the item is removed and the carret is placed at the end of the previous item. Pressing enter does not create a new item anymore.
BlockManager.removeBlock(index + 1); | ||
} else { | ||
/** If block is empty, just remove it */ | ||
BlockManager.removeBlock(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comment above, I don't think delete key should remove current block in any case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a windows user, I'm using the delete key more often for such tasks than the backspace key.
If you are selecting a block, pressing delete should delete it ( isn't that the point of the delete key, after all ? 😄 )
I have to admit though, that I copied that comment without understanding what it means. I don't see how it could be empty.
Thanks for the review. Should I rebase on the |
@jeremyVignelles yes please |
Pressing delete at the end of a block merges blocks (fixes codex-team#821) Pressing delete after a rectangular block selection removes the blocks (fixes codex-team#1315)
Co-authored-by: George Berezhnoy <[email protected]>
955e53b
to
b88931c
Compare
For some reason I can't merge anything except two paragraphs using delete key and also have noticed few more uncovered cases. Will investigate it on the weekend and get back to you |
Do the other "merges" work with the backspace key? |
You are right, they shouldn't, but there are some of my discovers:
|
I'm not sure, but I'd consider it a bug of the backspace key. I'm not sure that's something I would expect to be normal : If I pressed backspace instead of the left arrow key, that's because I wanted to destroy something, which obviously didn't work but had a "side effect" of moving the caret. EDIT : This seems to be explicitely wanted :
Other pointsSeems like the mergeBlocks methods assume that targetBlock is just before blockToMerge, but it doesn't handle well the cases you mentionned. I'm digging further and I'll get back to you |
So I fixed the 3 last points (in 3 different commits to make it easier to review). Thanks for testing and pointing that out ! As for the first point, I'm not sure how this should be handled: editor.js/src/components/modules/blockEvents.ts Lines 370 to 372 in 32ac52a
In this block, I dont know in which direction the merge occurred. Sure, I could detect it by the position of the caret, or by passing an additional parameter. Is that really something useful though ? For example, I'm on the image caption control : |
@jeremyVignelles agree the first point is arguable, I'm ok with the current behaviour, but it conflicts with backspace behaviour. Let's listen to @neSpecc and @khaydarov opinion. I've added some test cases, hope you don't mind |
Great, thanks for the test case, I never used cypress, I'll see how it works then 🙂 |
Anything else is needed here ? Can it be reviewed now ? |
@neSpecc @khaydarov take a look please |
Any updates on this? |
Just merged the latest "next" and tried to resolve the conflicts that I had. |
Hi, may I know what's the update on this? Thanks |
Hello! When? |
Hi there, we're also waiting for this solution, thanks! |
Any progress on this? |
Any news on that front ? |
Resolved by #2402 |
Pressing delete at the end of a block merges blocks (fixes #821)
Pressing delete after a rectangular block selection removes the blocks (fixes #1315)