mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-26 08:34:28 +02:00
Characters to leaves (#1816)
* Preparing tests * splitNode replacement * Remove slow splice; replace mergeNode * normalize Leaves * Partially remove characters * Partially remove characters * styling * Fix bugs; almost all characters are replaced * Fixes almost existing tests; preparing adding tests for text * Remove un-necessary check * Empty leaf * fix characters in getMarks * Faster fromJSON * Some corner cases for empty text * Fix naive bug * Supporting empty text with marks * Supporting empty text with marks in hyperscript * changes tests for marks in empty text * Support splitNode marks with empty text * Add tests for splitNode->insert * Faster removeText * Add warning ; remove getMarksAtIndex cache * Remove characters in getInsertMarkAtRange * Adding tests * Change names of tests * Update marks test * Add a test confirm for invalid offsets: * Add test for get active marks between offsets * Fix document * Add testing for insert-text * Better remove text * More sensible marks in empty text * Allow marks of empty text after deleting partially marked text * Add test for removing on partially marked text * chnage test structure * Add test for removeText * Add test for removeText * Avoid conflict between empty marked text and cursor * Simple style fixes * Simple style fixes * Line break fixes * Line break fixes * Annotate the createLeaves * Line breaks in test * Line breaks fix * add add-marks test * add merge test * Fix version update * Remove empty_leaf optimization; optimize of that will be other PRs * Clean up getMarksAtPosition * Fix get-insert-marks-at-range * clean up get-marks-at-position * Fix spaces
This commit is contained in:
committed by
Ian Storm Taylor
parent
c500becf81
commit
cb3a9a5528
@@ -273,7 +273,7 @@ function createChildren(children, options = {}) {
|
||||
const firstNodeOrText = children.find(c => typeof c !== 'string')
|
||||
const firstText = Text.isText(firstNodeOrText) ? firstNodeOrText : null
|
||||
const key = options.key ? options.key : firstText ? firstText.key : undefined
|
||||
let node = Text.create({ key })
|
||||
let node = Text.create({ key, leaves: [{ text: '', marks: options.marks }] })
|
||||
|
||||
// Create a helper to update the current node while preserving any stored
|
||||
// anchor or focus information.
|
||||
@@ -290,10 +290,18 @@ function createChildren(children, options = {}) {
|
||||
// If the child is a non-text node, push the current node and the new child
|
||||
// onto the array, then creating a new node for future selection tracking.
|
||||
if (Node.isNode(child) && !Text.isText(child)) {
|
||||
if (node.text.length || node.__anchor != null || node.__focus != null)
|
||||
if (
|
||||
node.text.length ||
|
||||
node.__anchor != null ||
|
||||
node.__focus != null ||
|
||||
node.getMarksAtIndex(0).size
|
||||
) {
|
||||
array.push(node)
|
||||
}
|
||||
array.push(child)
|
||||
node = isLast ? null : Text.create()
|
||||
node = isLast
|
||||
? null
|
||||
: Text.create({ leaves: [{ text: '', marks: options.marks }] })
|
||||
length = 0
|
||||
}
|
||||
|
||||
|
42
packages/slate-hyperscript/test/default/empty-marked-text.js
Normal file
42
packages/slate-hyperscript/test/default/empty-marked-text.js
Normal file
@@ -0,0 +1,42 @@
|
||||
/** @jsx h */
|
||||
|
||||
import h from '../..'
|
||||
|
||||
export const input = (
|
||||
<document>
|
||||
<block type="paragraph">
|
||||
<mark type="bold" />
|
||||
</block>
|
||||
</document>
|
||||
)
|
||||
|
||||
export const output = {
|
||||
object: 'document',
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
object: 'block',
|
||||
type: 'paragraph',
|
||||
isVoid: false,
|
||||
data: {},
|
||||
nodes: [
|
||||
{
|
||||
object: 'text',
|
||||
leaves: [
|
||||
{
|
||||
object: 'leaf',
|
||||
text: '',
|
||||
marks: [
|
||||
{
|
||||
type: 'bold',
|
||||
object: 'mark',
|
||||
data: {},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
Reference in New Issue
Block a user