@@ -62,7 +62,7 @@ class Block implements BlockModelInterface {
62
62
const editor = this . editor ;
63
63
if ( ! isEngine ( editor ) || editor . options . markdown ?. mode === false )
64
64
return ;
65
- const { change, block } = editor ;
65
+ const { change } = editor ;
66
66
let range = change . range . get ( ) ;
67
67
if ( ! range . collapsed || change . isComposing ( ) ) return ;
68
68
const { startNode, startOffset } = range ;
@@ -75,10 +75,10 @@ class Block implements BlockModelInterface {
75
75
if ( ! editor . node . isRootBlock ( blockNode ) ) return ;
76
76
const text = node . text ( ) . trimEnd ( ) ;
77
77
const cacheRange = range . toPath ( ) ;
78
- const markdown = createMarkdownIt ( this . editor , 'zero' ) ;
78
+ const markdown = createMarkdownIt ( editor , 'zero' ) ;
79
79
const tokens = markdown . parse ( text , { } ) ;
80
80
if ( tokens . length === 0 ) return ;
81
- const content = convertMarkdown ( this . editor , markdown , tokens , false ) ;
81
+ const content = convertMarkdown ( editor , markdown , tokens , false ) ;
82
82
if ( content ) {
83
83
event . preventDefault ( ) ;
84
84
range . select ( blockNode , true ) ;
@@ -182,8 +182,9 @@ class Block implements BlockModelInterface {
182
182
* @param range 光标
183
183
*/
184
184
wrap ( block : NodeInterface | Node | string , range ?: RangeInterface ) {
185
- if ( ! isEngine ( this . editor ) ) return ;
186
- const { change, node, schema, list, mark } = this . editor ;
185
+ const editor = this . editor ;
186
+ if ( ! isEngine ( editor ) ) return ;
187
+ const { change, node, schema, list, mark } = editor ;
187
188
const safeRange = range || change . range . toTrusty ( ) ;
188
189
const doc = getDocument ( safeRange . startContainer ) ;
189
190
if ( typeof block === 'string' || isNode ( block ) ) {
@@ -272,8 +273,9 @@ class Block implements BlockModelInterface {
272
273
* @param range 光标
273
274
*/
274
275
unwrap ( block : NodeInterface | Node | string , range ?: RangeInterface ) {
275
- if ( ! isEngine ( this . editor ) ) return ;
276
- const { change, node } = this . editor ;
276
+ const editor = this . editor ;
277
+ if ( ! isEngine ( editor ) ) return ;
278
+ const { change, node } = editor ;
277
279
const safeRange = range || change . range . toTrusty ( ) ;
278
280
const doc = getDocument ( safeRange . startContainer ) ;
279
281
if ( typeof block === 'string' || isNode ( block ) ) {
@@ -409,8 +411,9 @@ class Block implements BlockModelInterface {
409
411
* @param range 光标
410
412
*/
411
413
split ( range ?: RangeInterface ) {
412
- if ( ! isEngine ( this . editor ) ) return ;
413
- const { change, mark, nodeId } = this . editor ;
414
+ const editor = this . editor ;
415
+ if ( ! isEngine ( editor ) ) return ;
416
+ const { change, mark, nodeId } = editor ;
414
417
const safeRange = range || change . range . toTrusty ( ) ;
415
418
// 范围为展开状态时先删除内容
416
419
if ( ! safeRange . collapsed ) {
@@ -441,7 +444,7 @@ class Block implements BlockModelInterface {
441
444
cloneRange . shrinkToElementNode ( ) . shrinkToTextNode ( ) . collapse ( true ) ;
442
445
const activeMarks = mark . findMarks ( cloneRange ) . filter ( ( mark ) => {
443
446
// 回车后,默认是否复制makr样式
444
- const plugin = this . editor . mark . findPlugin ( mark ) ;
447
+ const plugin = editor . mark . findPlugin ( mark ) ;
445
448
return (
446
449
plugin ?. copyOnEnter !== false && plugin ?. followStyle !== false
447
450
) ;
@@ -453,7 +456,7 @@ class Block implements BlockModelInterface {
453
456
isLeft : false ,
454
457
keepDataId : true ,
455
458
} ) ;
456
- const nodeApi = this . editor . node ;
459
+ const nodeApi = editor . node ;
457
460
sideBlock . traverse ( ( node ) => {
458
461
if (
459
462
! nodeApi . isVoid ( node ) &&
@@ -498,12 +501,12 @@ class Block implements BlockModelInterface {
498
501
}
499
502
block . children ( ) . each ( ( child ) => {
500
503
if ( nodeApi . isInline ( child ) ) {
501
- this . editor . inline . repairCursor ( child ) ;
504
+ editor . inline . repairCursor ( child ) ;
502
505
}
503
506
} ) ;
504
507
sideBlock . children ( ) . each ( ( child ) => {
505
508
if ( nodeApi . isInline ( child ) ) {
506
- this . editor . inline . repairCursor ( child ) ;
509
+ editor . inline . repairCursor ( child ) ;
507
510
}
508
511
} ) ;
509
512
// 重新设置当前选中范围
@@ -533,8 +536,9 @@ class Block implements BlockModelInterface {
533
536
splitNode ?: ( node : NodeInterface ) => NodeInterface ,
534
537
removeCurrentEmptyBlock : boolean = false ,
535
538
) {
536
- if ( ! isEngine ( this . editor ) ) return ;
537
- const { change, node, list, inline } = this . editor ;
539
+ const editor = this . editor ;
540
+ if ( ! isEngine ( editor ) ) return ;
541
+ const { change, node, list, inline } = editor ;
538
542
const safeRange = range || change . range . toTrusty ( ) ;
539
543
const doc = getDocument ( safeRange . startContainer ) ;
540
544
if ( typeof block === 'string' || isNode ( block ) ) {
@@ -640,11 +644,11 @@ class Block implements BlockModelInterface {
640
644
! list . isEmptyItem ( rightNodes )
641
645
) {
642
646
const right = rightNodes . clone ( false ) ;
643
- this . editor . nodeId . generate ( right , true ) ;
647
+ editor . nodeId . generate ( right , true ) ;
644
648
const rightChildren = rightNodes . children ( ) ;
645
649
rightChildren . each ( ( child , index ) => {
646
650
if ( rightChildren . eq ( index ) ?. isCard ( ) ) {
647
- const card = this . editor . card . find ( child ) ;
651
+ const card = editor . card . find ( child ) ;
648
652
if ( card ) right . append ( card . root ) ;
649
653
} else right . append ( child ) ;
650
654
} ) ;
@@ -698,9 +702,10 @@ class Block implements BlockModelInterface {
698
702
* @param range 光标
699
703
*/
700
704
setBlocks ( block : string | { [ k : string ] : any } , range ?: RangeInterface ) {
701
- if ( ! isEngine ( this . editor ) ) return ;
702
- const { node, schema, mark } = this . editor ;
703
- const { change } = this . editor ;
705
+ const editor = this . editor ;
706
+ if ( ! isEngine ( editor ) ) return ;
707
+ const { node, schema, mark } = editor ;
708
+ const { change } = editor ;
704
709
const safeRange = range || change . range . toTrusty ( ) ;
705
710
const doc = getDocument ( safeRange . startContainer ) ;
706
711
let targetNode : NodeInterface | null = null ;
@@ -828,8 +833,9 @@ class Block implements BlockModelInterface {
828
833
* @param range 光标
829
834
*/
830
835
merge ( range ?: RangeInterface ) {
831
- if ( ! isEngine ( this . editor ) ) return ;
832
- const { change, schema } = this . editor ;
836
+ const editor = this . editor ;
837
+ if ( ! isEngine ( editor ) ) return ;
838
+ const { change, schema } = editor ;
833
839
const safeRange = range || change . range . toTrusty ( ) ;
834
840
const blocks = this . getBlocks ( safeRange ) ;
835
841
if ( 0 === blocks . length ) return ;
@@ -853,7 +859,7 @@ class Block implements BlockModelInterface {
853
859
Object . keys ( nextAttributes ) . join ( ',' ) ===
854
860
Object . keys ( prevAttributes || { } ) . join ( ',' )
855
861
) {
856
- this . editor . node . merge ( prevNode , nextNode ) ;
862
+ editor . node . merge ( prevNode , nextNode ) ;
857
863
}
858
864
nextNode = nextNode . next ( ) ;
859
865
}
@@ -866,11 +872,12 @@ class Block implements BlockModelInterface {
866
872
* 获取对范围有效果的所有 Block
867
873
*/
868
874
findBlocks ( range : RangeInterface ) {
875
+ const editor = this . editor ;
869
876
range = range . cloneRange ( ) ;
870
877
if ( range . startNode . isRoot ( ) ) range . shrinkToElementNode ( ) ;
871
878
if (
872
879
! range . startNode . inEditor ( ) ||
873
- this . editor . card . find ( range . startNode ) ?. type === CardType . BLOCK
880
+ editor . card . find ( range . startNode ) ?. type === CardType . BLOCK
874
881
)
875
882
return [ ] ;
876
883
const sc = range . startContainer ;
@@ -920,7 +927,7 @@ class Block implements BlockModelInterface {
920
927
if ( node . isEditable ( ) ) {
921
928
break ;
922
929
}
923
- if ( this . editor . node . isBlock ( node ) ) {
930
+ if ( editor . node . isBlock ( node ) ) {
924
931
nodes . push ( node ) ;
925
932
}
926
933
const parent = node . parent ( ) ;
@@ -936,7 +943,7 @@ class Block implements BlockModelInterface {
936
943
return addNode ( nodes , node , true ) ;
937
944
} ) ;
938
945
const { commonAncestorNode } = range ;
939
- const card = this . editor . card . find ( commonAncestorNode , true ) ;
946
+ const card = editor . card . find ( commonAncestorNode , true ) ;
940
947
let isEditable = card ?. isEditable ;
941
948
const selectionNodes = isEditable
942
949
? card ?. getSelectionNodes
@@ -956,7 +963,7 @@ class Block implements BlockModelInterface {
956
963
if (
957
964
child . isElement ( ) &&
958
965
! child . isCard ( ) &&
959
- this . editor . node . isBlock ( child )
966
+ editor . node . isBlock ( child )
960
967
) {
961
968
addNode ( nodes , child ) ;
962
969
}
@@ -982,13 +989,14 @@ class Block implements BlockModelInterface {
982
989
const block = this . closest ( container ) ;
983
990
range . select ( block , true ) ;
984
991
range . setEnd ( container [ 0 ] , offset ) ;
985
- if ( ! this . editor . node . isBlock ( container ) ) range . enlargeToElementNode ( ) ;
992
+ const editor = this . editor ;
993
+ if ( ! editor . node . isBlock ( container ) ) range . enlargeToElementNode ( ) ;
986
994
const fragment = range . cloneContents ( ) ;
987
995
988
996
if ( ! fragment . firstChild ) {
989
997
return true ;
990
998
}
991
- const { node } = this . editor ;
999
+ const { node } = editor ;
992
1000
if (
993
1001
fragment . childNodes . length === 1 &&
994
1002
$ ( fragment . firstChild ) . name === 'br'
@@ -1014,13 +1022,13 @@ class Block implements BlockModelInterface {
1014
1022
const block = this . closest ( container ) ;
1015
1023
range . select ( block , true ) ;
1016
1024
range . setStart ( container , offset ) ;
1017
- if ( ! this . editor . node . isBlock ( container ) ) range . enlargeToElementNode ( ) ;
1025
+ const { node } = this . editor ;
1026
+ if ( ! node . isBlock ( container ) ) range . enlargeToElementNode ( ) ;
1018
1027
const fragment = range . cloneContents ( ) ;
1019
1028
1020
1029
if ( ! fragment . firstChild ) {
1021
1030
return true ;
1022
1031
}
1023
- const { node } = this . editor ;
1024
1032
const emptyNode = $ ( '<div />' ) ;
1025
1033
emptyNode . append ( fragment ) ;
1026
1034
@@ -1035,8 +1043,8 @@ class Block implements BlockModelInterface {
1035
1043
range = range . cloneRange ( ) ;
1036
1044
range . shrinkToElementNode ( ) ;
1037
1045
range . shrinkToTextNode ( ) ;
1038
-
1039
- const { node } = this . editor ;
1046
+ const editor = this . editor ;
1047
+ const { node } = editor ;
1040
1048
1041
1049
let startBlock = this . closest ( range . startNode ) ;
1042
1050
if ( range . startNode . isRoot ( ) ) {
@@ -1051,7 +1059,7 @@ class Block implements BlockModelInterface {
1051
1059
const blocks : Array < NodeInterface > = [ ] ;
1052
1060
let started = false ;
1053
1061
const { commonAncestorNode } = range ;
1054
- const card = this . editor . card . find ( commonAncestorNode , true ) ;
1062
+ const card = editor . card . find ( commonAncestorNode , true ) ;
1055
1063
let isEditable = card ?. isEditable ;
1056
1064
const selectionNodes = isEditable
1057
1065
? card ?. getSelectionNodes
@@ -1071,7 +1079,7 @@ class Block implements BlockModelInterface {
1071
1079
}
1072
1080
if (
1073
1081
( started || isEditable ) &&
1074
- this . editor . node . isBlock ( child ) &&
1082
+ editor . node . isBlock ( child ) &&
1075
1083
! child . isCard ( ) &&
1076
1084
child . inEditor ( )
1077
1085
) {
@@ -1119,7 +1127,8 @@ class Block implements BlockModelInterface {
1119
1127
keepDataId ?: boolean ;
1120
1128
} ) {
1121
1129
if ( isNode ( block ) ) block = $ ( block ) ;
1122
- const newRange = Range . create ( this . editor , block . document ! ) ;
1130
+ const editor = this . editor ;
1131
+ const newRange = Range . create ( editor , block . document ! ) ;
1123
1132
1124
1133
if ( isLeft ) {
1125
1134
newRange . select ( block , true ) ;
@@ -1134,7 +1143,7 @@ class Block implements BlockModelInterface {
1134
1143
: newRange . extractContents ( ) ;
1135
1144
const cloneBlock = keepDataId
1136
1145
? block . clone ( false )
1137
- : this . editor . node . clone ( block , false , false ) ;
1146
+ : editor . node . clone ( block , false , false ) ;
1138
1147
cloneBlock . append ( fragement ) ;
1139
1148
if ( clone ) {
1140
1149
cloneBlock . find ( CARD_SELECTOR ) . each ( ( card ) => {
@@ -1152,8 +1161,9 @@ class Block implements BlockModelInterface {
1152
1161
* @param block 节点
1153
1162
*/
1154
1163
getLeftText ( block : NodeInterface | Node , range ?: RangeInterface ) {
1155
- if ( ! isEngine ( this . editor ) ) return '' ;
1156
- range = range || this . editor . change . range . get ( ) ;
1164
+ const editor = this . editor ;
1165
+ if ( ! isEngine ( editor ) ) return '' ;
1166
+ range = range || editor . change . range . get ( ) ;
1157
1167
const leftBlock = this . getBlockByRange ( {
1158
1168
block,
1159
1169
range,
@@ -1168,8 +1178,9 @@ class Block implements BlockModelInterface {
1168
1178
* @param block 节点
1169
1179
*/
1170
1180
removeLeftText ( block : NodeInterface | Node , range ?: RangeInterface ) {
1171
- if ( ! isEngine ( this . editor ) ) return ;
1172
- range = range || this . editor . change . range . get ( ) ;
1181
+ const editor = this . editor ;
1182
+ if ( ! isEngine ( editor ) ) return ;
1183
+ range = range || editor . change . range . get ( ) ;
1173
1184
if ( isNode ( block ) ) block = $ ( block ) ;
1174
1185
range . createSelection ( ) ;
1175
1186
const cursor = block . find ( CURSOR_SELECTOR ) ;
@@ -1194,8 +1205,9 @@ class Block implements BlockModelInterface {
1194
1205
* @param root 根节点
1195
1206
*/
1196
1207
flat ( block : NodeInterface , root : NodeInterface ) {
1197
- if ( ! isEngine ( this . editor ) ) return ;
1198
- const { schema, node } = this . editor ;
1208
+ const editor = this . editor ;
1209
+ if ( ! isEngine ( editor ) ) return ;
1210
+ const { schema, node } = editor ;
1199
1211
const mergeTags = schema . getCanMergeTags ( ) ;
1200
1212
//获取父级节点
1201
1213
let parentNode = block . parent ( ) ;
0 commit comments