File tree 2 files changed +13
-11
lines changed
2 files changed +13
-11
lines changed Original file line number Diff line number Diff line change @@ -383,18 +383,13 @@ class Quill {
383
383
( ) => {
384
384
delta = new Delta ( delta ) ;
385
385
const length = this . getLength ( ) ;
386
- const deleted = this . editor . deleteText ( 0 , length ) ;
386
+ // Quill will set empty editor to \n
387
+ const delete1 = this . editor . deleteText ( 0 , length ) ;
388
+ // delta always applied before existing content
387
389
const applied = this . editor . applyDelta ( delta ) ;
388
- const lastOp = applied . ops [ applied . ops . length - 1 ] ;
389
- if (
390
- lastOp != null &&
391
- typeof lastOp . insert === 'string' &&
392
- lastOp . insert [ lastOp . insert . length - 1 ] === '\n'
393
- ) {
394
- this . editor . deleteText ( this . getLength ( ) - 1 , 1 ) ;
395
- applied . delete ( 1 ) ;
396
- }
397
- return deleted . compose ( applied ) ;
390
+ // Remove extra \n from empty editor initialization
391
+ const delete2 = this . editor . deleteText ( this . getLength ( ) - 1 , 1 ) ;
392
+ return delete1 . compose ( applied ) . compose ( delete2 ) ;
398
393
} ,
399
394
source ,
400
395
) ;
Original file line number Diff line number Diff line change @@ -429,6 +429,13 @@ describe('Quill', function() {
429
429
expect ( quill . getContents ( ) ) . toEqual ( contents ) ;
430
430
expect ( delta ) . toEqual ( contents . delete ( contents . length ( ) ) ) ;
431
431
} ) ;
432
+
433
+ it ( 'block embed' , function ( ) {
434
+ const quill = this . initialize ( Quill , '<p>Hello World!</p>' ) ;
435
+ const contents = new Delta ( ) . insert ( { video : '#' } ) ;
436
+ quill . setContents ( contents ) ;
437
+ expect ( quill . getContents ( ) ) . toEqual ( contents ) ;
438
+ } ) ;
432
439
} ) ;
433
440
434
441
describe ( 'setText()' , function ( ) {
You can’t perform that action at this time.
0 commit comments