Skip to content
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

insertFragment fails on nested blocks #1493

Closed
Soreine opened this issue Dec 27, 2017 · 8 comments
Closed

insertFragment fails on nested blocks #1493

Soreine opened this issue Dec 27, 2017 · 8 comments

Comments

@Soreine
Copy link
Collaborator

Soreine commented Dec 27, 2017

Do you want to request a feature or report a bug?

A bug

What's the current behavior?

As of slate@0.31.7 go to http://slatejs.org/#/rich-text and triple click the quote "A wise quote." to select the whole line, then paste any piece of plain text here. This triggers insertFragmentAtRange which fails

Uncaught TypeError: Cannot read property 'key' of undefined
    at Changes.insertFragmentAtRange (http://slatejs.org/build.prod.js:5089:8501)
    at e.value (http://slatejs.org/build.prod.js:5125:2404)
    at e.Change.(anonymous function) [as insertFragmentAtRange] (http://slatejs.org/build.prod.js:5125:2880)
    at Changes.insertFragment (http://slatejs.org/build.prod.js:5086:1769)
    at e.value (http://slatejs.org/build.prod.js:5125:2404)
    at e.Change.(anonymous function) [as insertFragment] (http://slatejs.org/build.prod.js:5125:2880)
    at Object.f [as onPaste] (http://slatejs.org/build.prod.js:5032:5358)
    at t.value (http://slatejs.org/build.prod.js:5161:2517)
    at http://slatejs.org/build.prod.js:5001:5650
    at e.value (http://slatejs.org/build.prod.js:5125:2404)

What's the expected behavior?

It should not fail

This makes it hard to paste in code blocks or lists for example, depending on the nested structure your app is using.

@tobiasandersen
Copy link
Collaborator

This might be a stupid question, but what is the expected behavior here? Should it insert the pasted fragment into the quote-block (1), or should it replace the quote with the fragment (2/3)?

Let's say I paste the word "Hello", which of these are "correct"?

1:
screen shot 2018-01-18 at 13 20 27

2:
screen shot 2018-01-18 at 13 20 53

3:
screen shot 2018-01-18 at 13 21 07

Personally I feel like (1) makes more sense. But maybe there're other situations where that behavior could be problematic?

@dmitrizzle
Copy link

I'd expect (1) as that's what every other rich text editor does to my knowledge: paste and match style. Since that's what plain text is: data with no style association, meaning we have to assume some kind of style to it, which is usually derived from the location of paste.

@tobiasandersen
Copy link
Collaborator

I had a look at how Dropbox Paper handles it. If I at this point paste the word "Hello":

screen shot 2018-01-18 at 13 42 27

I actually end up with:

screen shot 2018-01-18 at 13 40 11

So I guess we have a fourth candidate:
4:
screen shot 2018-01-18 at 13 44 43

@ianstormtaylor
Copy link
Owner

I think (1) is the most expected.

There's a common issue that is when a user triple-clicks, they are usually referring to the idea of "the entire block", but the browser happens to put the focus point at the start of the next. Which explains the Dropbox Paper behavior, even though it's non-obvious.

That said, it might be harder to get that working to start, and we could start with the Dropbox Paper behavior if so.

@benjycui
Copy link
Contributor

Most of us expect 1. But why do we delete start block when selection is hanging?

// If the selection is hanging, just remove the start block, otherwise
// merge the end block into it.
if (isHanging) {
change.removeNodeByKey(startBlock.key, { normalize: false })
} else {
change.mergeNodeByKey(endBlock.key, { normalize: false })
}

IMO, we just need to clean children of start block, and we don't need to delete start block or merge end block.

@zhujinxuan
Copy link
Contributor

zhujinxuan commented Apr 25, 2018

@benjycui Because the hanging selection is when someone triple click in a block and select that block. Then it is alike select the whole block and then delete.

I make some fixes related, hopefully they will fix hanging->insert problems in next merge.
#1747 #1742 #1741

@ianstormtaylor
Copy link
Owner

See #2746

@ianstormtaylor
Copy link
Owner

I believe that this may be fixed by #3093, which has changed a lot of the logic in Slate and slate-react especially. I'm going to close this out, but as always, feel free to open a new issue if it persists for you. Thanks for understanding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants