1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-18 21:21:21 +02:00

fix bugs in rich text example

This commit is contained in:
Ian Storm Taylor
2016-06-21 17:08:15 -07:00
parent c3257a37d4
commit 38b85fe720
3 changed files with 11 additions and 16 deletions

View File

@@ -22,8 +22,8 @@ class App extends React.Component {
hasBlock(type) { hasBlock(type) {
const { state } = this.state const { state } = this.state
const { currentWrappingNodes } = state const { currentBlockNodes } = state
return currentWrappingNodes.some(node => node.type == type) return currentBlockNodes.some(node => node.type == type)
} }
onClickMark(e, type) { onClickMark(e, type) {

View File

@@ -549,16 +549,11 @@ const Node = {
hasNode(key) { hasNode(key) {
key = normalizeKey(key) key = normalizeKey(key)
return !! this.nodes.find((node) => {
const shallow = this.nodes.has(key) return node.kind == 'text'
if (shallow) return true ? node.key == key
: node.key == key || node.hasNode(key)
const deep = this.nodes })
.map(node => node.kind == 'text' ? false : node.hasNode(key))
.some(has => has)
if (deep) return true
return false
}, },
/** /**

View File

@@ -200,12 +200,12 @@ class State extends Record(DEFAULTS) {
const { startKey } = selection const { startKey } = selection
const startNode = document.getNode(startKey) const startNode = document.getNode(startKey)
if (selection.isAtStartOf(document)) { if (selection.isExpanded) {
after = selection after = selection.moveToStart()
} }
else if (selection.isExpanded) { else if (selection.isAtStartOf(document)) {
after = selection.moveToStart() after = selection
} }
else if (selection.isAtStartOf(startNode)) { else if (selection.isAtStartOf(startNode)) {