Preserve external history option (#22)

* feat: handle node text in remove_text op

* feat: add preserveExternalHistory option
This commit is contained in:
George
2020-07-02 00:56:48 +03:00
committed by GitHub
parent b49cf33464
commit 55b1b2ca5a
10 changed files with 72 additions and 36 deletions

View File

@@ -9,7 +9,9 @@ export const insertText = (
): SyncValue => {
const node = getTarget(doc, op.path)
node.text.insertAt(op.offset, ...op.text.split(''))
const offset = Math.min(node.text.length, op.offset)
node.text.insertAt(offset, ...op.text.split(''))
return doc
}
@@ -20,7 +22,9 @@ export const removeText = (
): SyncValue => {
const node = getTarget(doc, op.path)
node.text.deleteAt(op.offset, op.text.length)
const offset = Math.min(node.text.length, op.offset)
node.text.deleteAt(offset, op.text.length)
return doc
}