mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-18 13:11:17 +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:
committed by
Ian Storm Taylor
parent
09b15adb96
commit
ecc165740d
@@ -845,16 +845,16 @@ class Node {
|
|||||||
throw new Error(`Could not find a descendant node with key "${key}".`)
|
throw new Error(`Could not find a descendant node with key "${key}".`)
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
const result = ancestors
|
||||||
ancestors
|
// Skip this node...
|
||||||
// Skip this node...
|
.shift()
|
||||||
.skipLast()
|
// Take parents until there are more than one child...
|
||||||
// Take parents until there are more than one child...
|
.reverse()
|
||||||
.reverse()
|
.takeUntil(p => p.nodes.size > 1)
|
||||||
.takeUntil(p => p.nodes.size > 1)
|
// And pick the highest.
|
||||||
// And pick the highest.
|
.last()
|
||||||
.last()
|
if (!result) return null
|
||||||
)
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -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()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
21
packages/slate/test/models/node/get-furthest-only-child.js
Normal file
21
packages/slate/test/models/node/get-furthest-only-child.js
Normal 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)
|
||||||
|
}
|
Reference in New Issue
Block a user