fix: inline card set mark style

This commit is contained in:
yanmao 2021-12-24 14:31:17 +08:00
parent da2fb2b923
commit 76da0d7c9c
5 changed files with 40 additions and 8 deletions

View File

@ -265,6 +265,10 @@ class CardModel implements CardModelInterface {
if (isInline) {
if (isEngine(editor) && card.executeMark) {
marks = editor.change.marks.map((mark) => mark.clone());
const cardComponent = editor.card.find(range.startNode);
if (cardComponent?.queryMarks) {
marks.push(...cardComponent.queryMarks());
}
}
inline.insert(card.root, range);
} else {
@ -404,6 +408,8 @@ class CardModel implements CardModelInterface {
card.activate(true);
} else if (card.isEditable) {
card.select(false);
} else if (trigger === CardActiveTrigger.MOUSE_DOWN) {
event?.preventDefault();
}
if (
!isCurrentActiveCard &&

View File

@ -670,10 +670,10 @@
user-select: text;
}
.am-engine span[data-card-type="inline"].card-selected span[data-card-element="left"],
.am-engine-view span[data-card-type="inline"].card-selected span[data-card-element="left"],
.am-engine span[data-card-type="inline"].card-selected span[data-card-element="right"],
.am-engine-view span[data-card-type="inline"].card-selected span[data-card-element="right"] {
.am-engine span[data-card-type="inline"].card-selected:not(.card-activated) span[data-card-element="left"],
.am-engine-view span[data-card-type="inline"].card-selected:not(.card-activated) span[data-card-element="left"],
.am-engine span[data-card-type="inline"].card-selected:not(.card-activated) span[data-card-element="right"],
.am-engine-view span[data-card-type="inline"].card-selected:not(.card-activated) span[data-card-element="right"] {
background: rgba(180, 213, 254, 0.5) !important;
}

View File

@ -545,7 +545,7 @@ class Inline implements InlineModelInterface {
}
});
}
range.enlargeToElementNode();
range.enlargeToElementNode(!node.isBlock(range.startNode), false);
return keelpNode;
}
/**
@ -929,8 +929,21 @@ class Inline implements InlineModelInterface {
repairCursor(node: NodeInterface | Node) {
const nodeApi = this.editor.node;
if (isNode(node)) node = $(node);
if (!nodeApi.isInline(node) || nodeApi.isVoid(node) || node.isCard())
if (!nodeApi.isInline(node) || nodeApi.isVoid(node) || node.isCard()) {
const prev = node.prev();
const prevText = prev?.isText() ? prev.text() : undefined;
if (prevText && /\u200b$/.test(prevText)) {
const pPrev = prev?.prev();
if (!pPrev || !nodeApi.isInline(pPrev)) {
if (prevText.length === 1) {
prev?.remove();
} else {
prev?.text(prevText.slice(0, -1));
}
}
}
return;
}
const childrenNodes = node.children();
childrenNodes.each((_, index) => {
const child = childrenNodes.eq(index);

View File

@ -299,8 +299,12 @@ class Range implements RangeInterface {
* <p>[<strong><span>123</span>abc</strong>]def</p>
* @param range
* @param toBlock
* @param toTop
*/
enlargeToElementNode = (toBlock?: boolean) => {
enlargeToElementNode = (
toBlock: boolean = false,
toTop: boolean = true,
) => {
const range = this.enlargeFromTextNode();
const nodeApi = this.editor.node;
const enlargePosition = (
@ -326,6 +330,10 @@ class Range implements RangeInterface {
if (!parent.inEditor() || parent.isEditable()) {
break;
}
if (!toTop) {
if (!toBlock && parent.isElement()) break;
if (toBlock && nodeApi.isBlock(parent)) break;
}
domNode = parent;
}
if (isStart) {
@ -342,6 +350,10 @@ class Range implements RangeInterface {
if (!parent.inEditor() || parent.isEditable()) {
break;
}
if (!toTop) {
if (!toBlock && parent.isElement()) break;
if (toBlock && nodeApi.isBlock(parent)) break;
}
domNode = parent;
}
if (isStart) {

View File

@ -200,8 +200,9 @@ export interface RangeInterface {
* <p>[<strong><span>123</span>abc</strong>]def</p>
* @param range
* @param toBlock
* @param toTop
*/
enlargeToElementNode(toBlock?: boolean): RangeInterface;
enlargeToElementNode(toBlock?: boolean, toTop?: boolean): RangeInterface;
/**
*
* <body>[<p><strong>123</strong></p>]</body>