fix: warpByNode filter cursor node

This commit is contained in:
yanmao 2021-12-24 14:47:30 +08:00
parent 76da0d7c9c
commit 97b7bd9b39
4 changed files with 12 additions and 8 deletions

View File

@ -759,19 +759,22 @@ class Mark implements MarkModelInterface {
if (!nodeApi.isEmpty(node)) {
//找到最底层mark标签添加包裹<strong><span style="font-size:16px">abc</span></strong> ,在 span 节点中的text再添加包裹不在strong外添加包裹
let targetNode = node;
let targetChildrens = targetNode.children();
let targetChildrens = targetNode.children().toArray();
const curPlugin = this.findPlugin(targetNode);
while (
nodeApi.isMark(targetNode) &&
targetChildrens.length === 1 &&
targetChildrens.filter((child) => !child.isCursor())
.length === 1 &&
plugin &&
curPlugin &&
plugin.mergeLeval <= curPlugin.mergeLeval
) {
const targetChild = targetChildrens.eq(0)!;
const targetChild = targetChildrens.find(
(child) => !child.isCursor(),
)!;
if (nodeApi.isMark(targetChild)) {
targetNode = targetChild;
targetChildrens = targetNode.children();
targetChildrens = targetNode.children().toArray();
} else if (targetChild.isText()) {
targetNode = targetChild;
} else break;

View File

@ -7,7 +7,7 @@ export default class<T extends BackcolorOptions> extends MarkPlugin<T> {
static get pluginName() {
return 'backcolor';
}
readonly mergeLeval = 4;
tagName = 'span';
style = {

View File

@ -7,7 +7,7 @@ export default class<T extends FontcolorOptions> extends MarkPlugin<T> {
static get pluginName() {
return 'fontcolor';
}
readonly mergeLeval = 3;
tagName = 'span';
style = {

View File

@ -139,9 +139,10 @@ export default class<T extends PaintformatOptions> extends Plugin<T> {
paintMarks(activeMarks: NodeInterface[]) {
const { mark } = this.editor!;
activeMarks.forEach((node) => {
for (let i = activeMarks.length - 1; i >= 0; i--) {
const node = activeMarks[i];
mark.wrap(this.editor.node.clone(node, false, false));
});
}
}
paintBlocks(currentBlock: NodeInterface, activeBlocks: NodeInterface[]) {