Merge pull request #690 from yjs/revert-689-patch-1

Revert "fix(yText): applyDelta should support both Delta and Ops[]"
This commit is contained in:
Kevin Jahns 2025-01-12 19:33:12 +01:00 committed by GitHub
commit 2d2e662d4d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -972,16 +972,15 @@ export class YText extends AbstractType {
if (this.doc !== null) {
transact(this.doc, transaction => {
const currPos = new ItemTextListPosition(null, this._start, 0, new Map())
const ops = Array.isArray(delta) ? delta : (Array.isArray(delta?.ops) ? delta.ops : []);
for (let i = 0; i < ops.length; i++) {
const op = ops[i]
for (let i = 0; i < delta.length; i++) {
const op = delta[i]
if (op.insert !== undefined) {
// Quill assumes that the content starts with an empty paragraph.
// Yjs/Y.Text assumes that it starts empty. We always hide that
// there is a newline at the end of the content.
// If we omit this step, clients will see a different number of
// paragraphs, but nothing bad will happen.
const ins = (!sanitize && typeof op.insert === 'string' && i === ops.length - 1 && currPos.right === null && op.insert.slice(-1) === '\n') ? op.insert.slice(0, -1) : op.insert
const ins = (!sanitize && typeof op.insert === 'string' && i === delta.length - 1 && currPos.right === null && op.insert.slice(-1) === '\n') ? op.insert.slice(0, -1) : op.insert
if (typeof ins !== 'string' || ins.length > 0) {
insertText(transaction, this, currPos, ins, op.attributes || {})
}