mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-09 08:46:35 +02:00
Improved merging of blocks when deleting text (#3258)
This commit is contained in:
committed by
Ian Storm Taylor
parent
ed974222a9
commit
8982ba9b2f
@@ -66,26 +66,31 @@ export const TextTransforms = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let [start, end] = Range.edges(at)
|
let [start, end] = Range.edges(at)
|
||||||
const [ancestor] = Editor.ancestor(editor, at)
|
const startBlock = Editor.match(editor, start.path, 'block')
|
||||||
|
const endBlock = Editor.match(editor, end.path, 'block')
|
||||||
|
const isAcrossBlocks =
|
||||||
|
startBlock && endBlock && !Path.equals(startBlock[1], endBlock[1])
|
||||||
const isSingleText = Path.equals(start.path, end.path)
|
const isSingleText = Path.equals(start.path, end.path)
|
||||||
const startVoid = Editor.match(editor, start.path, 'void')
|
const startVoid = Editor.match(editor, start.path, 'void')
|
||||||
const endVoid = Editor.match(editor, end.path, 'void')
|
const endVoid = Editor.match(editor, end.path, 'void')
|
||||||
|
|
||||||
// If the start or end points are inside an inline void, nudge them out.
|
// If the start or end points are inside an inline void, nudge them out.
|
||||||
if (startVoid) {
|
if (startVoid) {
|
||||||
const block = Editor.match(editor, start.path, 'block')
|
|
||||||
const before = Editor.before(editor, start)
|
const before = Editor.before(editor, start)
|
||||||
|
|
||||||
if (before && block && Path.isAncestor(block[1], before.path)) {
|
if (
|
||||||
|
before &&
|
||||||
|
startBlock &&
|
||||||
|
Path.isAncestor(startBlock[1], before.path)
|
||||||
|
) {
|
||||||
start = before
|
start = before
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (endVoid) {
|
if (endVoid) {
|
||||||
const block = Editor.match(editor, end.path, 'block')
|
|
||||||
const after = Editor.after(editor, end)
|
const after = Editor.after(editor, end)
|
||||||
|
|
||||||
if (after && block && Path.isAncestor(block[1], after.path)) {
|
if (after && endBlock && Path.isAncestor(endBlock[1], after.path)) {
|
||||||
end = after
|
end = after
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -127,13 +132,9 @@ export const TextTransforms = {
|
|||||||
editor.apply({ type: 'remove_text', path, offset, text })
|
editor.apply({ type: 'remove_text', path, offset, text })
|
||||||
}
|
}
|
||||||
|
|
||||||
const isBlockAncestor =
|
|
||||||
Editor.isEditor(ancestor) ||
|
|
||||||
(Element.isElement(ancestor) && !editor.isInline(ancestor))
|
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!isSingleText &&
|
!isSingleText &&
|
||||||
isBlockAncestor &&
|
isAcrossBlocks &&
|
||||||
endRef.current &&
|
endRef.current &&
|
||||||
startRef.current
|
startRef.current
|
||||||
) {
|
) {
|
||||||
|
@@ -0,0 +1,28 @@
|
|||||||
|
/** @jsx jsx */
|
||||||
|
|
||||||
|
import { Editor } from 'slate'
|
||||||
|
import { jsx } from '../../..'
|
||||||
|
|
||||||
|
export const run = editor => {
|
||||||
|
Editor.delete(editor)
|
||||||
|
}
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<editor>
|
||||||
|
<block>one</block>
|
||||||
|
<block>
|
||||||
|
t<anchor />
|
||||||
|
wo<inline>three</inline>fou
|
||||||
|
<focus />r
|
||||||
|
</block>
|
||||||
|
</editor>
|
||||||
|
)
|
||||||
|
|
||||||
|
export const output = (
|
||||||
|
<editor>
|
||||||
|
<block>one</block>
|
||||||
|
<block>
|
||||||
|
t<cursor />r
|
||||||
|
</block>
|
||||||
|
</editor>
|
||||||
|
)
|
Reference in New Issue
Block a user