editor.js icon indicating copy to clipboard operation
editor.js copied to clipboard

Added handling for delete key

Open jeremyVignelles opened this issue 4 years ago • 16 comments

Pressing delete at the end of a block merges blocks (fixes #821) Pressing delete after a rectangular block selection removes the blocks (fixes #1315)

jeremyVignelles avatar Apr 05 '21 12:04 jeremyVignelles

Thanks for the review. Should I rebase on the next branch to integrate the new commits ?

jeremyVignelles avatar Apr 08 '21 20:04 jeremyVignelles

@jeremyVignelles yes please

gohabereg avatar Apr 08 '21 20:04 gohabereg

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

gohabereg avatar Apr 08 '21 21:04 gohabereg

Do the other "merges" work with the backspace key?

jeremyVignelles avatar Apr 08 '21 21:04 jeremyVignelles

You are right, they shouldn't, but there are some of my discovers:

Pre-requirements Steps Actual Expected
Two not-empty different blocks one by one Set cursor to the end of the first block and press delete Nothing is happen If the same happens for backspace, caret is set to the previous block. So for delete I'd expect caret to set to the next block
Not-empty block and then an empty block - "" - - "" - I'd expect empty Block to be deleted
- "" - Set cursor to the empty block and press delete Block is deleted, caret is set to previous block I'd expect caret to be set to the next block
Not-empty block and then block without inputs (eg Delimiter) Set cursor to the end of the first block and press delete Nothing is happen I'd expect Delimiter to be deleted

gohabereg avatar Apr 09 '21 14:04 gohabereg

Two not-empty different blocks one by one

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 : https://github.com/codex-team/editor.js/blob/32ac52a62fb1e36dddaad1f9fe224e46a931f056/src/components/modules/blockEvents.ts#L357 . I'm still not sure that's a desired behavior, but I can match that the other way around

Other points

Seems 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

jeremyVignelles avatar Apr 10 '21 09:04 jeremyVignelles

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:

https://github.com/codex-team/editor.js/blob/32ac52a62fb1e36dddaad1f9fe224e46a931f056/src/components/modules/blockEvents.ts#L370-L372

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 : image I made an error, and I press backspace to the beginning of the input, as I am not patient, I'm holding down the backspace key, until everything is removed. If I don't release the key on time, the caret is moved to the previous block, and starts removing code above.

jeremyVignelles avatar Apr 10 '21 10:04 jeremyVignelles

@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

gohabereg avatar Apr 11 '21 20:04 gohabereg

Great, thanks for the test case, I never used cypress, I'll see how it works then 🙂

jeremyVignelles avatar Apr 11 '21 21:04 jeremyVignelles

Anything else is needed here ? Can it be reviewed now ?

jeremyVignelles avatar Apr 22 '21 07:04 jeremyVignelles

@neSpecc @khaydarov take a look please

gohabereg avatar Apr 22 '21 20:04 gohabereg

Any updates on this?

hyun-park avatar Aug 26 '21 02:08 hyun-park

Just merged the latest "next" and tried to resolve the conflicts that I had. Ready again for review

jeremyVignelles avatar Oct 09 '21 10:10 jeremyVignelles

Hi, may I know what's the update on this? Thanks

mbagsik00 avatar Jan 27 '22 20:01 mbagsik00

Hello! When?

NeoKms avatar May 13 '22 08:05 NeoKms

Hi there, we're also waiting for this solution, thanks!

julianpeterson1 avatar May 26 '22 11:05 julianpeterson1

Any progress on this?

kimchi-hent avatar Jan 31 '23 09:01 kimchi-hent

Any news on that front ?

cicelle avatar Aug 09 '23 07:08 cicelle

Resolved by #2402 Available starting 2.28.0-rc.1 2.28 will be released this week.

neSpecc avatar Aug 09 '23 11:08 neSpecc