1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-04-20 21:34:53 +02:00

fix: error getting parentEntry in selection range (#5168)

Co-authored-by: Steven Zhong <stevenzhong@StevendeMacBook-Pro-2.local>
This commit is contained in:
Steven.zhong 2022-11-08 20:37:53 +08:00 committed by GitHub
parent e61678da14
commit 3c49ff28b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 50 additions and 2 deletions

View File

@ -0,0 +1,5 @@
---
'slate': patch
---
Fixed above method that failed to get parentEntry when selection was range

View File

@ -357,8 +357,18 @@ export const Editor: EditorInterface = {
match,
reverse,
})) {
if (!Text.isText(n) && !Path.equals(path, p)) {
return [n, p]
if (Text.isText(n)) return
if (Range.isRange(at)) {
if (
Path.isAncestor(p, at.anchor.path) &&
Path.isAncestor(p, at.focus.path)
) {
return [n, p]
}
} else {
if (!Path.equals(path, p)) {
return [n, p]
}
}
}
},

View File

@ -0,0 +1,33 @@
/** @jsx jsx */
import { Editor } from 'slate'
import { jsx } from '../../..'
export const input = (
<editor>
<block>
<block>
<block>one</block>
</block>
<block>two</block>
</block>
</editor>
)
const range = {
anchor: { offset: 0, path: [0, 0, 0, 0] },
focus: { offset: 0, path: [0, 1, 0] },
}
export const test = editor => {
return Editor.above(editor, {
at: range,
match: n => Editor.isBlock(editor, n),
})
}
export const output = [
<block>
<block>
<block>one</block>
</block>
<block>two</block>
</block>,
[0],
]