mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-06 15:26:34 +02:00
fix a few void block transform and rendering bugs
This commit is contained in:
@@ -324,7 +324,7 @@ class Content extends React.Component {
|
|||||||
focusKey: focus.key,
|
focusKey: focus.key,
|
||||||
focusOffset: focus.offset
|
focusOffset: focus.offset
|
||||||
})
|
})
|
||||||
.apply({ isNative: true })
|
.apply()
|
||||||
|
|
||||||
this.onChange(state)
|
this.onChange(state)
|
||||||
}
|
}
|
||||||
|
@@ -763,6 +763,17 @@ const Node = {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a node has a void parent by `key`.
|
||||||
|
*
|
||||||
|
* @param {String or Node} key
|
||||||
|
* @return {Boolean}
|
||||||
|
*/
|
||||||
|
|
||||||
|
hasVoidParent(key) {
|
||||||
|
return !!this.getClosest(key, n => n.isVoid)
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Insert child `nodes` after child by `key`.
|
* Insert child `nodes` after child by `key`.
|
||||||
*
|
*
|
||||||
@@ -772,7 +783,6 @@ const Node = {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
insertChildrenAfter(key, nodes) {
|
insertChildrenAfter(key, nodes) {
|
||||||
key = normalizeKey(key)
|
|
||||||
const child = this.getChild(key)
|
const child = this.getChild(key)
|
||||||
const index = this.nodes.indexOf(child)
|
const index = this.nodes.indexOf(child)
|
||||||
|
|
||||||
|
@@ -560,9 +560,17 @@ class State extends new Record(DEFAULTS) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
else if (selection.isAtStartOf(startNode)) {
|
else if (selection.isAtStartOf(startNode)) {
|
||||||
const parent = document.getParent(startNode)
|
const previous = document.getPreviousText(startNode)
|
||||||
const previous = document.getPreviousSibling(parent).nodes.first()
|
const prevBlock = document.getClosestBlock(previous)
|
||||||
after = selection.collapseToEndOf(previous)
|
const prevInline = document.getClosestInline(previous)
|
||||||
|
|
||||||
|
if (prevBlock && prevBlock.isVoid) {
|
||||||
|
after = selection
|
||||||
|
} else if (prevInline && prevInline.isVoid) {
|
||||||
|
after = selection
|
||||||
|
} else {
|
||||||
|
after = selection.collapseToEndOf(previous)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else {
|
else {
|
||||||
|
@@ -117,6 +117,14 @@ const Transforms = {
|
|||||||
|
|
||||||
if (range.isAtStartOf(startNode)) {
|
if (range.isAtStartOf(startNode)) {
|
||||||
const previous = node.getPreviousText(startNode)
|
const previous = node.getPreviousText(startNode)
|
||||||
|
|
||||||
|
// If the previous descendant is void, remove it.
|
||||||
|
const prevBlock = node.getClosestBlock(previous)
|
||||||
|
if (prevBlock && prevBlock.isVoid) return node.removeDescendant(prevBlock)
|
||||||
|
|
||||||
|
const prevInline = node.getClosestInline(previous)
|
||||||
|
if (prevInline && prevInline.isVoid) return node.removeDescendant(prevInline)
|
||||||
|
|
||||||
range = range.extendToEndOf(previous)
|
range = range.extendToEndOf(previous)
|
||||||
range = range.normalize(node)
|
range = range.normalize(node)
|
||||||
return node.deleteAtRange(range)
|
return node.deleteAtRange(range)
|
||||||
|
@@ -147,11 +147,18 @@ function Plugin(options = {}) {
|
|||||||
|
|
||||||
onKeyDown(e, state, editor) {
|
onKeyDown(e, state, editor) {
|
||||||
const key = keycode(e.which)
|
const key = keycode(e.which)
|
||||||
const transform = state.transform()
|
let transform = state.transform()
|
||||||
|
|
||||||
switch (key) {
|
switch (key) {
|
||||||
case 'enter': {
|
case 'enter': {
|
||||||
return transform.splitBlock().apply()
|
const { startBlock } = state
|
||||||
|
if (startBlock && !startBlock.isVoid) return transform.splitBlock().apply()
|
||||||
|
|
||||||
|
const { document, startKey } = state
|
||||||
|
const text = document.getNextText(startKey)
|
||||||
|
if (!text) return
|
||||||
|
|
||||||
|
return transform.collapseToStartOf(text).apply()
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'backspace': {
|
case 'backspace': {
|
||||||
|
Reference in New Issue
Block a user