Skip to content

Commit

Permalink
insertContents fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
luin committed Jun 30, 2023
1 parent 0877563 commit a6b7b02
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
17 changes: 14 additions & 3 deletions blots/scroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ class Scroll extends ScrollBlot {
const last = lines.pop();
let after;
if (last != null) {
after = child.split(offset + first.delta.length());
after = child.split(offset + first.delta.length(), true);
Object.keys(first.attributes).forEach(name => {
// @ts-ignore
child.format(name, first.attributes[name]);
after.prev.format(name, first.attributes[name]);
});
after.insertContents(0, last.delta);
}
Expand All @@ -185,9 +185,20 @@ class Scroll extends ScrollBlot {
blockAttribute || this.statics.defaultChild.blotName,
blockAttribute ? attributes[blockAttribute] : undefined,
);
this.insertBefore(block, after);
// @ts-ignore
block.insertContents(0, lineDelta);
this.insertBefore(block, after);
Object.keys(attributes).forEach(key => {
if (
this.query(
key,
// eslint-disable-next-line no-bitwise
Scope.BLOCK & Scope.BLOT,
) == null
) {
block.formatAt(0, block.length(), key, attributes[key]);
}
});
});

this.batchEnd();
Expand Down
5 changes: 3 additions & 2 deletions core/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,9 @@ class Editor {
}

insertContents(index: number, contents: Delta): Delta {
const change = new Delta().retain(index).concat(contents);
this.scroll.insertContents(index, contents);
const normalizedDelta = normalizeDelta(contents);
const change = new Delta().retain(index).concat(normalizedDelta);
this.scroll.insertContents(index, normalizedDelta);
return this.update(change);
}

Expand Down

0 comments on commit a6b7b02

Please sign in to comment.