Slate: cmd+backspace deletes the entire block, not just the current line

Created on 8 Feb 2018  Â·  14Comments  Â·  Source: ianstormtaylor/slate

Do you want to request a _feature_ or report a _bug_?

Bug.

What's the current behavior?

Here's a gif of the problem in our Slate editor, compared with a native mac app like textedit. Command and backspace currently deletes the entire paragraph/block. Although the gif shows our use case, this is easily reproducible on the examples at http://slatejs.org/.

image

What's the expected behavior?

Only the current line should be deleted.

Note: cmd+shift creates the correct selection, so one way of phrasing the expected behavior is "it should do what cmd+shift, followed by backspace, does today".

improvement ♥ help

Most helpful comment

@ianstormtaylor It becomes much easier if we do not need to consider react-native.
I will submit a PR next weekend

All 14 comments

@steobrien this is a tricky one. The reason we do until the start of the block is because I think it's hard (or impossible, not sure?) to determine where lines start/end and how that converts back into which characters to erase.

I'm open to ideas here for how to achieve it!

Got it. My first thought was to try and copy the cmd+shift implementation, as that leads to the correct selection of just the current line.

Or perhaps Slate defers to the browser for that?

@steobrien yup, we defer to the browser for the selection handling on that I believe.

Hi, I published a package on npm with name slate-delete-one-line to fix the problem.

Can you have a try?

import LineDelete from 'slate-delete-one-line'
const plugin = LineDelete()

Hey @zhujinxuan, I've taken this for a spin and it seems to work great!

Very cool @zhujinxuan! If you wanted to PR that, I'd love to be able to have that behavior in core. I didn't realize it was even possible 😄

@steobrien Great. The package address is https://github.com/zhujinxuan/slate-sensible
I will finish the tests and document this weekend.

@ianstormtaylor I'd like to submit the PR. But the solution depends on get rect bound of range. It seems react-native does not support DOMRange.getBoundingClient? Is there a polyfill way to get Rect for Android and iOS?

@zhujinxuan I’m not sure. Although I think we already do tons of stuff that’s not react native compatible?

@ianstormtaylor It becomes much easier if we do not need to consider react-native.
I will submit a PR next weekend

Hey @zhujinxuan, slate-delete-one-line is working pretty nicely for us, but I’m wondering if you’re still planning to add this to core? I posted a bounty a while back in case that helps!

@steobrien Sorry. I am not planning to add it to core at this moment, because these codes cannot be tested in slate-react currently. I think I will add it to slate-core after I get slate-react tested with Chrome headless.

This should now be easier to do, by overriding the delete_forward/delete_backward commands only when the unit: 'line' for DOM behaviors. If someone wants to add this to the withReact plugin that would be awesome!

👋 Hi all. I've linked #3364 which addresses this issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

markolofsen picture markolofsen  Â·  3Comments

ezakto picture ezakto  Â·  3Comments

AlexeiAndreev picture AlexeiAndreev  Â·  3Comments

bunterWolf picture bunterWolf  Â·  3Comments

Slapbox picture Slapbox  Â·  3Comments