diff --git a/blots/scroll.ts b/blots/scroll.ts index 2ef177c4f2..74e2093189 100644 --- a/blots/scroll.ts +++ b/blots/scroll.ts @@ -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); } @@ -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(); diff --git a/core/editor.ts b/core/editor.ts index df1b741386..961785ced5 100644 --- a/core/editor.ts +++ b/core/editor.ts @@ -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); }