@@ -5,18 +5,28 @@ import lowestMatchedAncestor from '../../matchers/lowestMatchedAncestor';
5
5
function unwrapIfCursorAtStart ( editor , mergeWithPrevious = false ) {
6
6
if ( editor . selection . anchor . offset !== 0 ) return false ;
7
7
8
- const node = Editor . above ( editor , lowestMatchedAncestor ( editor , 'non-default' ) ) ;
8
+ let [ node , path ] = Editor . above ( editor , lowestMatchedAncestor ( editor , 'non-default' ) ) ;
9
9
10
- if ( node [ 1 ] . length == 0 ) return false ;
10
+ if ( path . length == 0 ) return false ;
11
11
12
- const isHeading = `${ node [ 0 ] . type } ` . startsWith ( 'heading-' ) ;
12
+ const isHeading = `${ node . type } ` . startsWith ( 'heading-' ) ;
13
13
if ( isHeading ) {
14
14
Transforms . setNodes ( editor , { type : 'paragraph' } ) ;
15
15
return false ;
16
16
}
17
17
18
+ const isBlock = Editor . isBlock ( editor , node ) ;
19
+ const [ parentBlock , parentBlockPath ] = Editor . above ( editor , lowestMatchedAncestor ( editor , 'block' ) ) ;
20
+ if ( ! isBlock ) {
21
+ if ( ! Editor . isStart ( editor , path , parentBlockPath ) ) {
22
+ return false ;
23
+ }
24
+
25
+ [ node , path ] = [ parentBlock , parentBlockPath ] ;
26
+ }
27
+
18
28
Editor . withoutNormalizing ( editor , ( ) => {
19
- Transforms . unwrapNodes ( editor , { match : n => n . type === node [ 0 ] . type , split : true } ) ;
29
+ Transforms . unwrapNodes ( editor , { match : n => n . type === node . type , split : true } ) ;
20
30
21
31
if ( mergeWithPrevious ) {
22
32
Transforms . mergeNodes ( editor ) ;
0 commit comments