@@ -10,7 +10,7 @@ import { Editor, Point, Range } from "doc-editor-delta";
1010import { isEmptyValue , isObject } from "laser-utils" ;
1111
1212import { getBlockNode } from "./get" ;
13- import { isBlock , isText } from "./ref" ;
13+ import { getParentNode , isBlock , isText } from "./ref" ;
1414
1515export const isWrappedNode = ( editor : Editor ) => {
1616 const match = getBlockNode ( editor ) ;
@@ -129,30 +129,23 @@ export const isMatchWrapNode = (
129129 const location = at || editor . selection ;
130130 if ( ! location ) return false ;
131131 const current = Editor . node ( editor , location ) ;
132+ const currentNode = current && current [ 0 ] ;
132133 // https://github.com/ianstormtaylor/slate/blob/25be3b/packages/slate/src/interfaces/editor.ts#L1062
133- const parent = Editor . parent ( editor , location ) ;
134- if ( current && parent ) {
135- const [ node ] = current ;
136- const [ parentNode ] = parent ;
137- if (
138- isBlock ( editor , node ) &&
139- isBlock ( editor , parentNode ) &&
140- node [ pairKey ] &&
141- parentNode [ wrapKey ]
142- ) {
134+ const parent = getParentNode ( editor , location ) ;
135+ const parentNode = parent && parent [ 0 ] ;
136+ // 如果当前节点即块元素 检查当前块和父级块匹配关系
137+ if ( isBlock ( editor , currentNode ) && isBlock ( editor , parentNode ) ) {
138+ if ( currentNode [ pairKey ] && parentNode [ wrapKey ] ) {
143139 return true ;
144140 }
141+ // 在这种情况下应该是只检查
142+ return false ;
145143 }
146- const ancestor = parent && Editor . parent ( editor , parent [ 1 ] ) ;
147- if ( parent && ancestor ) {
148- const [ node ] = parent ;
149- const [ parentNode ] = ancestor ;
150- if (
151- isBlock ( editor , node ) &&
152- isBlock ( editor , parentNode ) &&
153- node [ pairKey ] &&
154- parentNode [ wrapKey ]
155- ) {
144+ const ancestor = parent && getParentNode ( editor , parent [ 1 ] ) ;
145+ const ancestorNode = ancestor && ancestor [ 0 ] ;
146+ // 检查父级块和祖先块匹配关系
147+ if ( isBlock ( editor , parentNode ) && isBlock ( editor , ancestorNode ) ) {
148+ if ( parentNode [ pairKey ] && ancestorNode [ wrapKey ] ) {
156149 return true ;
157150 }
158151 }
0 commit comments