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:
parent
e61678da14
commit
3c49ff28b3
5
.changeset/tame-melons-clap.md
Normal file
5
.changeset/tame-melons-clap.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
'slate': patch
|
||||
---
|
||||
|
||||
Fixed above method that failed to get parentEntry when selection was range
|
@ -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]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
33
packages/slate/test/interfaces/Editor/above/range.tsx
Normal file
33
packages/slate/test/interfaces/Editor/above/range.tsx
Normal 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],
|
||||
]
|
Loading…
x
Reference in New Issue
Block a user