update: when marks are stored, do not nest

This commit is contained in:
yanmao 2021-12-27 22:42:54 +08:00
parent 606fa7bae2
commit 4169dbf395
3 changed files with 32 additions and 7 deletions

View File

@ -295,7 +295,7 @@ export default class<T extends MarkRangeOptions> extends MarkPlugin<T> {
subRanges.forEach((subRange) => { subRanges.forEach((subRange) => {
//如果是卡片,就给卡片加上预览样式 //如果是卡片,就给卡片加上预览样式
const cardComponent = card.find(subRange.startNode); const cardComponent = card.find(subRange.startNode);
if (cardComponent) { if (cardComponent && !cardComponent.executeMark) {
text += `[card:${ text += `[card:${
(cardComponent.constructor as CardEntry).cardName (cardComponent.constructor as CardEntry).cardName
},${cardComponent.id}]`; },${cardComponent.id}]`;
@ -670,8 +670,17 @@ export default class<T extends MarkRangeOptions> extends MarkPlugin<T> {
const rangeClone = range.cloneRange(); const rangeClone = range.cloneRange();
if (childNode.isCard()) { if (childNode.isCard()) {
const cardComponent = card.find(childNode);
if (cardComponent && cardComponent.executeMark) {
const idName = this.getIdName(key);
const markNode = cardComponent.root.find(
`[${idName}="${id}"]`,
);
cardComponent.executeMark(markNode.clone(), false);
} else {
childNode.removeAttributes(this.getIdName(key));
}
rangeClone.select(childNode); rangeClone.select(childNode);
childNode.removeAttributes(this.getIdName(key));
} else { } else {
rangeClone.select(childNode, true); rangeClone.select(childNode, true);
const selection = rangeClone.createSelection(); const selection = rangeClone.createSelection();
@ -765,7 +774,21 @@ export default class<T extends MarkRangeOptions> extends MarkPlugin<T> {
elements.forEach((element) => { elements.forEach((element) => {
const node = $(element); const node = $(element);
if (node.isCard()) { if (node.isCard()) {
node.attributes(this.getIdName(key), id.join(',')); const cardComponent = card.find(node);
if (cardComponent && cardComponent.executeMark) {
cardComponent.executeMark(
$(
`<${this.tagName} ${
this.MARK_KEY
}="${key}" ${this.getIdName(key)}="${id.join(
',',
)}" />`,
),
true,
);
} else {
node.attributes(this.getIdName(key), id.join(','));
}
} }
}); });
this.editor.mark.wrap( this.editor.mark.wrap(

View File

@ -294,7 +294,7 @@ class Mention<T extends MentionValue = MentionValue> extends Card<T> {
if (child) this.editor.mark.wrapByNode(child, mark); if (child) this.editor.mark.wrapByNode(child, mark);
}); });
const marks = this.queryMarks().map( const marks = this.queryMarks().map(
(child) => child.get<HTMLElement>()?.outerHTML || '', (child) => child.clone().get<HTMLElement>()?.outerHTML || '',
); );
this.setValue({ this.setValue({
marks, marks,
@ -315,7 +315,8 @@ class Mention<T extends MentionValue = MentionValue> extends Card<T> {
if (!this.#container) return []; if (!this.#container) return [];
return this.#container return this.#container
.allChildren() .allChildren()
.filter((child) => child.isElement()); .filter((child) => child.isElement())
.map((c) => c.clone());
} }
render(): string | void | NodeInterface { render(): string | void | NodeInterface {

View File

@ -192,7 +192,7 @@ class Status<T extends StatusValue = StatusValue> extends Card<T> {
if (child) this.editor.mark.wrapByNode(child, mark); if (child) this.editor.mark.wrapByNode(child, mark);
}); });
const marks = this.queryMarks().map( const marks = this.queryMarks().map(
(child) => child.get<HTMLElement>()?.outerHTML || '', (child) => child.clone().get<HTMLElement>()?.outerHTML || '',
); );
this.setValue({ this.setValue({
marks, marks,
@ -214,7 +214,8 @@ class Status<T extends StatusValue = StatusValue> extends Card<T> {
if (!this.#container) return []; if (!this.#container) return [];
return this.#container return this.#container
.allChildren() .allChildren()
.filter((child) => child.isElement()); .filter((child) => child.isElement())
.map((c) => c.clone());
} }
focusEditor() { focusEditor() {