You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
cudr_slate-collaborative/packages/bridge/src/apply/text.ts

26 lines
586 B

import { InsertTextOperation, RemoveTextOperation } from 'slate'
import { getTarget } from '../path'
import { SyncDoc } from '../model'
export const insertText = (doc: SyncDoc, op: InsertTextOperation): SyncDoc => {
const node = getTarget(doc, op.path)
node.text.insertAt(op.offset, ...op.text.split(''))
return doc
}
export const removeText = (doc: SyncDoc, op: RemoveTextOperation): SyncDoc => {
const node = getTarget(doc, op.path)
node.text.deleteAt(op.offset, op.text.length)
return doc
}
export default {
insert_text: insertText,
remove_text: removeText
}