@@ -239,15 +239,34 @@ watch(
239
239
240
240
watch (
241
241
() => textContent .value ,
242
- (newValue , oldValue ) => {
243
- const isSame = newValue === editor .value ?.getHTML ();
242
+ (newValue ) => {
243
+ const innerHTML = getInnerHTML (editor .value );
244
+ const isSame = newValue === innerHTML ;
244
245
if (isSame ) {
245
246
return ;
246
247
}
247
248
editor .value ?.commands .setContent (newValue || " " , false );
248
249
},
249
250
);
250
251
252
+ const getInnerHTML = (editor : Editor | null ) => {
253
+ if (! editor ) {
254
+ return " " ;
255
+ }
256
+ let innerHTML = editor .isEmpty ? " " : editor .getHTML ();
257
+ if (
258
+ props .block .isHeader () &&
259
+ ! (
260
+ editor .isActive (" heading" , { level: 1 }) ||
261
+ editor .isActive (" heading" , { level: 2 }) ||
262
+ editor .isActive (" heading" , { level: 3 })
263
+ )
264
+ ) {
265
+ innerHTML = editor ?.getText ();
266
+ }
267
+ return innerHTML ;
268
+ };
269
+
251
270
if (! props .preview ) {
252
271
watch (
253
272
() => store .activeCanvas ?.isSelected (props .block ),
@@ -268,17 +287,7 @@ if (!props.preview) {
268
287
],
269
288
enablePasteRules: false ,
270
289
onUpdate({ editor }) {
271
- let innerHTML = editor .isEmpty ? " " : editor .getHTML ();
272
- if (
273
- props .block .isHeader () &&
274
- ! (
275
- editor .isActive (" heading" , { level: 1 }) ||
276
- editor .isActive (" heading" , { level: 2 }) ||
277
- editor .isActive (" heading" , { level: 3 })
278
- )
279
- ) {
280
- innerHTML = editor .getText ();
281
- }
290
+ let innerHTML = getInnerHTML (editor as Editor );
282
291
if (props .block .getInnerHTML () === innerHTML ) {
283
292
return ;
284
293
}
0 commit comments