mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-28 17:39:57 +02:00
cleanup
This commit is contained in:
@@ -408,12 +408,12 @@ const Node = {
|
|||||||
getNextSibling(key) {
|
getNextSibling(key) {
|
||||||
key = normalizeKey(key)
|
key = normalizeKey(key)
|
||||||
|
|
||||||
const shallow = this.nodes
|
if (this.nodes.has(key)) {
|
||||||
.skipUntil(node => node.key == key)
|
return this.nodes
|
||||||
.rest()
|
.skipUntil(node => node.key == key)
|
||||||
.first()
|
.rest()
|
||||||
|
.first()
|
||||||
if (shallow != null) return shallow
|
}
|
||||||
|
|
||||||
return this.nodes
|
return this.nodes
|
||||||
.map(node => node.kind == 'text' ? null : node.getNextSibling(key))
|
.map(node => node.kind == 'text' ? null : node.getNextSibling(key))
|
||||||
@@ -437,7 +437,7 @@ const Node = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the child text node at an `offset`.
|
* Get the offset for a child text node by `key`.
|
||||||
*
|
*
|
||||||
* @param {String or Node} key
|
* @param {String or Node} key
|
||||||
* @return {Number} offset
|
* @return {Number} offset
|
||||||
@@ -447,7 +447,7 @@ const Node = {
|
|||||||
this.assertHasDeep(key)
|
this.assertHasDeep(key)
|
||||||
const match = this.getDeep(key)
|
const match = this.getDeep(key)
|
||||||
|
|
||||||
// Get all of the nodes that come before the matching child.
|
// Find the shallow matching child.
|
||||||
const child = this.nodes.find((node) => {
|
const child = this.nodes.find((node) => {
|
||||||
if (node == match) return true
|
if (node == match) return true
|
||||||
return node.kind == 'text'
|
return node.kind == 'text'
|
||||||
@@ -455,6 +455,7 @@ const Node = {
|
|||||||
: node.hasDeep(match)
|
: node.hasDeep(match)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Get all of the nodes that come before the matching child.
|
||||||
const befores = this.nodes.takeUntil(node => node.key == child.key)
|
const befores = this.nodes.takeUntil(node => node.key == child.key)
|
||||||
|
|
||||||
// Calculate the offset of the nodes before the matching child.
|
// Calculate the offset of the nodes before the matching child.
|
||||||
@@ -480,8 +481,8 @@ const Node = {
|
|||||||
key = normalizeKey(key)
|
key = normalizeKey(key)
|
||||||
|
|
||||||
if (this.nodes.get(key)) return this
|
if (this.nodes.get(key)) return this
|
||||||
let node = null
|
|
||||||
|
|
||||||
|
let node = null
|
||||||
this.nodes.forEach((child) => {
|
this.nodes.forEach((child) => {
|
||||||
if (child.kind == 'text') return
|
if (child.kind == 'text') return
|
||||||
const match = child.getParent(key)
|
const match = child.getParent(key)
|
||||||
@@ -501,9 +502,7 @@ const Node = {
|
|||||||
getPreviousSibling(key) {
|
getPreviousSibling(key) {
|
||||||
key = normalizeKey(key)
|
key = normalizeKey(key)
|
||||||
|
|
||||||
const matches = this.nodes.get(key)
|
if (this.nodes.has(key)) {
|
||||||
|
|
||||||
if (matches) {
|
|
||||||
return this.nodes
|
return this.nodes
|
||||||
.takeUntil(node => node.key == key)
|
.takeUntil(node => node.key == key)
|
||||||
.last()
|
.last()
|
||||||
@@ -538,7 +537,7 @@ const Node = {
|
|||||||
|
|
||||||
getTextAtOffset(offset) {
|
getTextAtOffset(offset) {
|
||||||
let length = 0
|
let length = 0
|
||||||
let texts = this.filterDeep(node => node.kind == 'text')
|
let texts = this.getTextNodes()
|
||||||
let match = texts.find((node) => {
|
let match = texts.find((node) => {
|
||||||
length += node.length
|
length += node.length
|
||||||
return length >= offset
|
return length >= offset
|
||||||
|
Reference in New Issue
Block a user