1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-12 02:03:59 +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:
Jinxuan Zhu
2018-06-14 22:39:41 -04:00
committed by Ian Storm Taylor
parent c500becf81
commit cb3a9a5528
55 changed files with 1407 additions and 194 deletions

View File

@@ -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
}