mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-17 20:51:20 +02:00
fix selection coercing when removing nodes
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
|||||||
Descendant,
|
Descendant,
|
||||||
Path,
|
Path,
|
||||||
} from '../../..'
|
} from '../../..'
|
||||||
|
import { TextEntry } from '../../text'
|
||||||
|
|
||||||
export const DIRTY_PATHS: WeakMap<Editor, Path[]> = new WeakMap()
|
export const DIRTY_PATHS: WeakMap<Editor, Path[]> = new WeakMap()
|
||||||
|
|
||||||
@@ -166,8 +167,6 @@ export const GeneralTransforms = {
|
|||||||
const { path } = op
|
const { path } = op
|
||||||
const index = path[path.length - 1]
|
const index = path[path.length - 1]
|
||||||
const parent = Node.parent(editor, path)
|
const parent = Node.parent(editor, path)
|
||||||
const [, prev] = Node.texts(editor, { from: path, reverse: true })
|
|
||||||
const [, next] = Node.texts(editor, { from: path })
|
|
||||||
parent.children.splice(index, 1)
|
parent.children.splice(index, 1)
|
||||||
|
|
||||||
// Transform all of the points in the value, but if the point was in the
|
// Transform all of the points in the value, but if the point was in the
|
||||||
@@ -178,17 +177,31 @@ export const GeneralTransforms = {
|
|||||||
|
|
||||||
if (selection != null && result != null) {
|
if (selection != null && result != null) {
|
||||||
selection[key] = result
|
selection[key] = result
|
||||||
} else if (prev) {
|
|
||||||
const [prevNode, prevPath] = prev
|
|
||||||
point.path = prevPath
|
|
||||||
point.offset = prevNode.text.length
|
|
||||||
} else if (next) {
|
|
||||||
const [, nextPath] = next
|
|
||||||
const newNextPath = Path.transform(nextPath, op)!
|
|
||||||
point.path = newNextPath
|
|
||||||
point.offset = 0
|
|
||||||
} else {
|
} else {
|
||||||
selection = null
|
let found = false
|
||||||
|
let prev: TextEntry | undefined
|
||||||
|
let next: TextEntry | undefined
|
||||||
|
|
||||||
|
for (const [n, p] of Node.texts(editor)) {
|
||||||
|
if (Path.compare(p, path) === -1) {
|
||||||
|
prev = [n, p]
|
||||||
|
} else {
|
||||||
|
next = [n, p]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found) {
|
||||||
|
if (prev) {
|
||||||
|
point.path = prev[1]
|
||||||
|
point.offset = prev[0].text.length
|
||||||
|
} else if (next) {
|
||||||
|
point.path = next[1]
|
||||||
|
point.offset = 0
|
||||||
|
} else {
|
||||||
|
selection = null
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,30 @@
|
|||||||
|
/** @jsx jsx */
|
||||||
|
|
||||||
|
import { Editor } from 'slate'
|
||||||
|
import { jsx } from '../../..'
|
||||||
|
|
||||||
|
export const input = (
|
||||||
|
<editor>
|
||||||
|
<block void>
|
||||||
|
<text>
|
||||||
|
<cursor />
|
||||||
|
one
|
||||||
|
</text>
|
||||||
|
<text>two</text>
|
||||||
|
</block>
|
||||||
|
<block>three</block>
|
||||||
|
</editor>
|
||||||
|
)
|
||||||
|
|
||||||
|
export const run = editor => {
|
||||||
|
Editor.removeNodes(editor, { at: [0] })
|
||||||
|
}
|
||||||
|
|
||||||
|
export const output = (
|
||||||
|
<editor>
|
||||||
|
<block>
|
||||||
|
<cursor />
|
||||||
|
three
|
||||||
|
</block>
|
||||||
|
</editor>
|
||||||
|
)
|
Reference in New Issue
Block a user