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

Fix skip this in getFurtherstLonelyAncestor (#1628)

* Fix skip this in getFurtherstLonelyAncestor

* export runTest in models/

* Change the path of test getOnlyChildAncestor

* Update index.js

* Update get-furthest-only-child.js

* Fix for linting
This commit is contained in:
Jinxuan Zhu
2018-03-21 18:26:56 -04:00
committed by Ian Storm Taylor
parent 09b15adb96
commit ecc165740d
3 changed files with 48 additions and 10 deletions

View File

@@ -845,16 +845,16 @@ class Node {
throw new Error(`Could not find a descendant node with key "${key}".`)
}
return (
ancestors
// Skip this node...
.skipLast()
// Take parents until there are more than one child...
.reverse()
.takeUntil(p => p.nodes.size > 1)
// And pick the highest.
.last()
)
const result = ancestors
// Skip this node...
.shift()
// Take parents until there are more than one child...
.reverse()
.takeUntil(p => p.nodes.size > 1)
// And pick the highest.
.last()
if (!result) return null
return result
}
/**

View File

@@ -33,4 +33,21 @@ describe('models', () => {
}
})
})
describe('node', () => {
describe('node', () => {
const testsDir = resolve(__dirname, 'node')
const tests = fs
.readdirSync(testsDir)
.filter(t => t[0] != '.')
.map(t => basename(t, extname(t)))
for (const test of tests) {
it(test, async () => {
const run = require(resolve(testsDir, test)).default
run()
})
}
})
})
})

View File

@@ -0,0 +1,21 @@
/** @jsx h */
import h from '../../helpers/h'
import assert from 'assert'
export default function() {
const { document } = (
<value>
<document>
<paragraph>Some Text</paragraph>
</document>
</value>
)
const paragraph = document.nodes.first()
const text = paragraph.getFirstText()
assert.equal(document.getFurthestOnlyChildAncestor(paragraph.key), null)
assert.equal(paragraph.getFurthestOnlyChildAncestor(text.key), null)
assert.equal(document.getFurthestOnlyChildAncestor(text.key), paragraph)
}