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