mirror of
https://github.com/cudr/slate-collaborative.git
synced 2025-06-13 12:54:04 +00:00
25 lines
572 B
TypeScript
25 lines
572 B
TypeScript
import { SyncDoc } from '../model'
|
|
import { InsertTextOperation, RemoveTextOperation } from 'slate'
|
|
import { getTarget } from '../path'
|
|
|
|
export const insertText = (doc: SyncDoc, op: InsertTextOperation): SyncDoc => {
|
|
const node = getTarget(doc, op.path)
|
|
|
|
node.text.insertAt(op.offset, op.text)
|
|
|
|
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
|
|
}
|