mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-07-31 20:40:19 +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:
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,
|
match,
|
||||||
reverse,
|
reverse,
|
||||||
})) {
|
})) {
|
||||||
if (!Text.isText(n) && !Path.equals(path, p)) {
|
if (Text.isText(n)) return
|
||||||
return [n, p]
|
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],
|
||||||
|
]
|
Reference in New Issue
Block a user