From 0b435cb094567b2150de9d02df4c1af9926ba1f8 Mon Sep 17 00:00:00 2001 From: Zihua Li Date: Thu, 1 Jun 2023 22:08:49 +0800 Subject: [PATCH] Fix embed inherits formats unexpectedly --- core/editor.ts | 3 +++ test/unit/core/editor.js | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/core/editor.ts b/core/editor.ts index 0b7e8c4aee..5b4b6a9a49 100644 --- a/core/editor.ts +++ b/core/editor.ts @@ -62,6 +62,9 @@ class Editor { ) { isImplicitNewlineAppended = true; } + const [leaf] = this.scroll.leaf(index); + const formats = merge({}, bubbleFormats(leaf)); + attributes = AttributeMap.diff(formats, attributes) || {}; } else if (index > 0) { // @ts-expect-error const [leaf, offset] = this.scroll.descendant(LeafBlot, index - 1); diff --git a/test/unit/core/editor.js b/test/unit/core/editor.js index 162865c63a..542c896063 100644 --- a/test/unit/core/editor.js +++ b/test/unit/core/editor.js @@ -517,6 +517,16 @@ describe('Editor', function () { ); }); + it('insert inline embed to the middle of formatted content', function () { + const editor = this.initialize(Editor, '

0123

'); + editor.applyDelta( + new Delta().retain(2).insert({ image: '/assets/favicon.png' }), + ); + expect(this.container).toEqualHTML( + '

0123

', + ); + }); + it('insert block embed with delete before block embed', function () { const editor = this.initialize( Editor,