fix: mark cannot filter existing styles when wrapping nested warp

This commit is contained in:
yanmao 2021-12-28 11:06:39 +08:00
parent 4169dbf395
commit 2c78a582bb
1 changed files with 18 additions and 6 deletions

View File

@ -844,10 +844,17 @@ class Mark implements MarkModelInterface {
nodeApi.removeZeroWidthSpace(node); nodeApi.removeZeroWidthSpace(node);
let parent = node.parent(); let parent = node.parent();
//父级和当前要包裹的节点,属性和值都相同,那就不包裹。只有属性一样,并且父节点只有一个节点那就移除父节点包裹,然后按插件情况合并值 //父级和当前要包裹的节点,属性和值都相同,那就不包裹。只有属性一样,并且父节点只有一个节点那就移除父节点包裹,然后按插件情况合并值
if (parent && nodeApi.isMark(parent)) { let result = false;
if (this.compare(parent.clone(), mark, true)) return false; while (parent && nodeApi.isMark(parent)) {
if (parent.children().length === 1) { if (this.compare(parent.clone(), mark, true)) {
const plugin = this.findPlugin(mark); result = true;
break;
} else if (
parent
.children()
.toArray()
.filter((node) => !node.isCursor()).length === 1
) {
const curPlugin = this.findPlugin(parent); const curPlugin = this.findPlugin(parent);
//插件一样,并且并表明要合并值 //插件一样,并且并表明要合并值
if ( if (
@ -856,15 +863,20 @@ class Mark implements MarkModelInterface {
plugin.combineValueByWrap === true plugin.combineValueByWrap === true
) { ) {
nodeApi.wrap(parent, mark, true); nodeApi.wrap(parent, mark, true);
return parent; result = true;
break;
} }
//插件一样,不合并,直接移除 //插件一样,不合并,直接移除
else if (plugin && plugin === curPlugin) { else if (plugin && plugin === curPlugin) {
nodeApi.unwrap(parent); nodeApi.unwrap(parent);
parent = node.parent(); result = false;
break;
} }
} }
parent = parent.parent();
} }
if (result) return false;
let targetNode = parent; let targetNode = parent;
let curPlugin = targetNode let curPlugin = targetNode
? this.findPlugin(targetNode) ? this.findPlugin(targetNode)