mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-04-21 13:51:59 +02:00
bleh, revert some stuff
This commit is contained in:
parent
e0e909f075
commit
2b32e0269c
@ -72,49 +72,17 @@ const Node = {
|
||||
return node
|
||||
}
|
||||
|
||||
// Determine the start edge text nodes.
|
||||
// Split the blocks and determine the edge boundaries.
|
||||
const start = range.moveToStart()
|
||||
const startFurthest = node.getFurthestBlock(startKey)
|
||||
let startText
|
||||
let startEdgeText
|
||||
|
||||
if (range.hasEdgeAtStartOf(startFurthest)) {
|
||||
startText = node.getPreviousText(startKey)
|
||||
startEdgeText = node.getDescendant(startKey)
|
||||
}
|
||||
|
||||
else if (range.hasEdgeAtEndOf(startFurthest)) {
|
||||
startText = node.getDescendant(startKey)
|
||||
startEdgeText = node.getNextText(startKey)
|
||||
}
|
||||
|
||||
else {
|
||||
node = node.splitBlockAtRange(start, Infinity)
|
||||
startText = node.getDescendant(startKey)
|
||||
startEdgeText = node.getNextText(startKey)
|
||||
}
|
||||
|
||||
// Determine the end edge text nodes.
|
||||
const end = range.moveToEnd()
|
||||
const endFurthest = node.getFurthestBlock(endKey)
|
||||
let endText
|
||||
let endEdgeText
|
||||
node = node.splitBlockAtRange(start, Infinity)
|
||||
node = node.splitBlockAtRange(end, Infinity)
|
||||
|
||||
if (range.hasEdgeAtStartOf(endFurthest)) {
|
||||
endEdgeText = node.getPreviousText(endKey)
|
||||
endText = node.getDescendant(endKey)
|
||||
}
|
||||
const startText = node.getDescendant(startKey)
|
||||
const startEdgeText = node.getNextText(startKey)
|
||||
|
||||
else if (range.hasEdgeAtEndOf(endFurthest)) {
|
||||
endEdgeText = node.getDescendant(endKey)
|
||||
endText = node.getNextText(endKey)
|
||||
}
|
||||
|
||||
else {
|
||||
node = node.splitBlockAtRange(end, Infinity)
|
||||
endEdgeText = node.getDescendant(endKey)
|
||||
endText = node.getNextText(endKey)
|
||||
}
|
||||
const endText = node.getNextText(endKey)
|
||||
const endEdgeText = node.getDescendant(endKey)
|
||||
|
||||
// Remove the new blocks inside the edges.
|
||||
const startEdgeBlock = node.getFurthestBlock(startEdgeText)
|
||||
@ -174,16 +142,12 @@ const Node = {
|
||||
const previous = node.getPreviousText(startNode)
|
||||
range = range.extendToEndOf(previous)
|
||||
range = range.normalize(node)
|
||||
node = node.deleteAtRange(range)
|
||||
return node
|
||||
return node.deleteAtRange(range)
|
||||
}
|
||||
|
||||
// Otherwise, remove `n` characters behind of the cursor.
|
||||
range = range.extendBackward(n)
|
||||
node = node.deleteAtRange(range)
|
||||
|
||||
// Normalize the node.
|
||||
return node.normalize()
|
||||
return node.deleteAtRange(range)
|
||||
},
|
||||
|
||||
/**
|
||||
@ -212,16 +176,12 @@ const Node = {
|
||||
const next = node.getNextText(startNode)
|
||||
range = range.extendToStartOf(next)
|
||||
range = range.normalize(node)
|
||||
node = node.deleteAtRange(range)
|
||||
return node
|
||||
return node.deleteAtRange(range)
|
||||
}
|
||||
|
||||
// Otherwise, remove `n` characters ahead of the cursor.
|
||||
range = range.extendForward(n)
|
||||
node = node.deleteAtRange(range)
|
||||
|
||||
// Normalize the node.
|
||||
return node.normalize()
|
||||
return node.deleteAtRange(range)
|
||||
},
|
||||
|
||||
/**
|
||||
@ -902,23 +862,11 @@ const Node = {
|
||||
range = range.moveToStart()
|
||||
}
|
||||
|
||||
// If at the start of end of the node, do nothing.
|
||||
if (range.isAtStartOf(node) || range.isAtEndOf(node)) return node
|
||||
|
||||
// If at the start of end of the closest block, do nothing.
|
||||
const { startKey } = range
|
||||
const block = node.getClosestBlock(startKey)
|
||||
if (range.isAtStartOf(block) || range.isAtEndOf(block)) return node
|
||||
|
||||
// If not at the edge of the furthest inline, split it.
|
||||
const text = node.getDescendant(startKey)
|
||||
const furthest = node.getFurthestInline(text) || text
|
||||
|
||||
if (!range.isAtStartOf(furthest) && !range.isAtEndOf(furthest)) {
|
||||
node = node.splitInlineAtRange(range)
|
||||
}
|
||||
// Split the inline nodes at the range.
|
||||
node = node.splitInlineAtRange(range)
|
||||
|
||||
// Find the highest inline elements that were split.
|
||||
const { startKey } = range
|
||||
const firstText = node.getDescendant(startKey)
|
||||
const secondText = node.getNextText(startKey)
|
||||
let firstChild = node.getFurthestInline(firstText) || firstText
|
||||
@ -974,36 +922,13 @@ const Node = {
|
||||
range = range.moveToStart()
|
||||
}
|
||||
|
||||
// If at the start or end of the node, do nothing.
|
||||
if (range.isAtStartOf(node) || range.isAtEndOf(node)) return node
|
||||
|
||||
// If at the start or the end of the furthest inline, do nothing.
|
||||
const { startKey } = range
|
||||
const text = node.getDescendant(startKey)
|
||||
const furthest = node.getFurthestInline(text) || text
|
||||
if (range.isAtStartOf(furthest) || range.isAtEndOf(furthest)) return node
|
||||
|
||||
// Determine the first and next nodes based on the edge.
|
||||
let firstChild
|
||||
let secondChild
|
||||
|
||||
if (range.isAtStartOf(text)) {
|
||||
firstChild = node.getPreviousText(startKey)
|
||||
secondChild = node.getDescendant(startKey)
|
||||
}
|
||||
|
||||
else if (range.isAtEndOf(text)) {
|
||||
firstChild = node.getDescendant(startKey)
|
||||
secondChild = node.getNextText(firstChild)
|
||||
}
|
||||
|
||||
else {
|
||||
node = node.splitTextAtRange(range)
|
||||
firstChild = node.getDescendant(startKey)
|
||||
secondChild = node.getNextText(firstChild)
|
||||
}
|
||||
|
||||
// First split the text nodes.
|
||||
node = node.splitTextAtRange(range)
|
||||
|
||||
// Find the children that were split.
|
||||
const { startKey } = range
|
||||
let firstChild = node.getDescendant(startKey)
|
||||
let secondChild = node.getNextText(firstChild)
|
||||
let parent = node.getClosestInline(firstChild)
|
||||
let d = 0
|
||||
|
||||
@ -1053,12 +978,9 @@ const Node = {
|
||||
range = range.moveToStart()
|
||||
}
|
||||
|
||||
// If at the start or the end of the text node, do nothing.
|
||||
// Split the text node's characters.
|
||||
const { startKey, startOffset } = range
|
||||
const text = node.getDescendant(startKey)
|
||||
if (range.isAtStartOf(text) || range.isAtEndOf(text)) return node
|
||||
|
||||
// Split the text node's characters.
|
||||
const { characters } = text
|
||||
const firstChars = characters.take(startOffset)
|
||||
const secondChars = characters.skip(startOffset)
|
||||
@ -1239,10 +1161,7 @@ const Node = {
|
||||
*/
|
||||
|
||||
updateDescendant(node) {
|
||||
// this.assertHasDescendant(key)
|
||||
|
||||
const shallow = this.nodes.find(child => child.key == node.key)
|
||||
if (shallow) {
|
||||
if (this.hasChild(node)) {
|
||||
const nodes = this.nodes.map(child => child.key == node.key ? node : child)
|
||||
return this.merge({ nodes })
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ class Selection extends Record(DEFAULTS) {
|
||||
isAtStartOf(node) {
|
||||
const { startKey, startOffset } = this
|
||||
const first = node.kind == 'text' ? node : node.getTextNodes().first()
|
||||
return startKey == first.key && startOffset == 0
|
||||
return this.isCollapsed && startKey == first.key && startOffset == 0
|
||||
}
|
||||
|
||||
/**
|
||||
@ -128,7 +128,7 @@ class Selection extends Record(DEFAULTS) {
|
||||
isAtEndOf(node) {
|
||||
const { endKey, endOffset } = this
|
||||
const last = node.kind == 'text' ? node : node.getTextNodes().last()
|
||||
return endKey == last.key && endOffset == last.length
|
||||
return this.isCollapsed && endKey == last.key && endOffset == last.length
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -6,3 +6,9 @@ nodes:
|
||||
- kind: text
|
||||
ranges:
|
||||
- text: word
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
ranges:
|
||||
- text: another
|
||||
|
@ -6,3 +6,15 @@ nodes:
|
||||
- kind: text
|
||||
ranges:
|
||||
- text: word
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
ranges:
|
||||
- text: ""
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
ranges:
|
||||
- text: another
|
||||
|
@ -2,11 +2,11 @@
|
||||
export default function (state) {
|
||||
const { document, selection } = state
|
||||
const texts = document.getTextNodes()
|
||||
const first = texts.first()
|
||||
const second = texts.get(1)
|
||||
const range = selection.merge({
|
||||
anchorKey: first.key,
|
||||
anchorKey: second.key,
|
||||
anchorOffset: 0,
|
||||
focusKey: first.key,
|
||||
focusKey: second.key,
|
||||
focusOffset: 0
|
||||
})
|
||||
|
||||
|
@ -6,3 +6,9 @@ nodes:
|
||||
- kind: text
|
||||
ranges:
|
||||
- text: word
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
ranges:
|
||||
- text: another
|
||||
|
@ -6,3 +6,15 @@ nodes:
|
||||
- kind: text
|
||||
ranges:
|
||||
- text: word
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
ranges:
|
||||
- text: ""
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: text
|
||||
ranges:
|
||||
- text: another
|
||||
|
@ -9,3 +9,9 @@ nodes:
|
||||
- kind: text
|
||||
ranges:
|
||||
- text: word
|
||||
- kind: inline
|
||||
type: link
|
||||
nodes:
|
||||
- kind: text
|
||||
ranges:
|
||||
- text: ""
|
||||
|
@ -3,6 +3,12 @@ nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: inline
|
||||
type: link
|
||||
nodes:
|
||||
- kind: text
|
||||
ranges:
|
||||
- text: ""
|
||||
- kind: inline
|
||||
type: link
|
||||
nodes:
|
||||
|
@ -1,18 +0,0 @@
|
||||
|
||||
export default function (state) {
|
||||
const { document, selection } = state
|
||||
const texts = document.getTextNodes()
|
||||
const first = texts.first()
|
||||
const second = texts.last()
|
||||
const range = selection.merge({
|
||||
anchorKey: first.key,
|
||||
anchorOffset: 2,
|
||||
focusKey: second.key,
|
||||
focusOffset: 2
|
||||
})
|
||||
|
||||
return state
|
||||
.transform()
|
||||
.splitInlineAtRange(range)
|
||||
.apply()
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: inline
|
||||
type: link
|
||||
nodes:
|
||||
- kind: text
|
||||
ranges:
|
||||
- text: word
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: inline
|
||||
type: link
|
||||
nodes:
|
||||
- kind: text
|
||||
ranges:
|
||||
- text: another
|
@ -1,17 +0,0 @@
|
||||
|
||||
nodes:
|
||||
- kind: block
|
||||
type: paragraph
|
||||
nodes:
|
||||
- kind: inline
|
||||
type: link
|
||||
nodes:
|
||||
- kind: text
|
||||
ranges:
|
||||
- text: wo
|
||||
- kind: inline
|
||||
type: link
|
||||
nodes:
|
||||
- kind: text
|
||||
ranges:
|
||||
- text: other
|
Loading…
x
Reference in New Issue
Block a user