This commit is contained in:
parent
317359c2dd
commit
402a7a205d
2 changed files with 47 additions and 4 deletions
|
@ -629,10 +629,10 @@ export class Toolbar {
|
|||
i--;
|
||||
} else {
|
||||
this.range.insertNode(currentNewNode);
|
||||
// https://github.com/siyuan-note/siyuan/issues/6155
|
||||
if (currentNewNode.nodeType !== 3 && ["code", "tag", "kbd"].includes(type)) {
|
||||
const previousSibling = hasPreviousSibling(currentNewNode);
|
||||
if (!previousSibling || previousSibling.textContent.endsWith("\n")) {
|
||||
if (currentNewNode.nodeType === 1 && ["code", "tag", "kbd"].includes(type)) {
|
||||
// 添加为 span https://github.com/siyuan-note/siyuan/issues/6155
|
||||
const currentPreviousSibling = hasPreviousSibling(currentNewNode);
|
||||
if (!currentPreviousSibling || currentPreviousSibling.textContent.endsWith("\n")) {
|
||||
currentNewNode.before(document.createTextNode(Constants.ZWSP));
|
||||
}
|
||||
if (!currentNewNode.textContent.startsWith(Constants.ZWSP)) {
|
||||
|
@ -647,6 +647,47 @@ export class Toolbar {
|
|||
) {
|
||||
currentNewNode.after(document.createTextNode(Constants.ZWSP));
|
||||
}
|
||||
} else if (currentNewNode.nodeType === 3 && ["code", "tag", "kbd", "clear"].includes(type)) {
|
||||
const currentPreviousSibling = hasPreviousSibling(currentNewNode) as HTMLElement;
|
||||
let previousIsCTK = false;
|
||||
if (currentPreviousSibling) {
|
||||
if (currentPreviousSibling.nodeType === 1) {
|
||||
const currentPreviousSiblingTypes = currentPreviousSibling.dataset.type.split(" ")
|
||||
if (currentPreviousSiblingTypes.includes("code") || currentPreviousSiblingTypes.includes("tag") || currentPreviousSiblingTypes.includes("kbd")) {
|
||||
previousIsCTK = true;
|
||||
}
|
||||
} else if (currentPreviousSibling.textContent.endsWith(Constants.ZWSP)) {
|
||||
currentPreviousSibling.textContent = currentPreviousSibling.textContent.substring(0, currentPreviousSibling.textContent.length - 1);
|
||||
}
|
||||
}
|
||||
const currentNextSibling = hasNextSibling(currentNewNode) as HTMLElement;
|
||||
let nextIsCTK = false;
|
||||
if (currentNextSibling) {
|
||||
if (currentNextSibling.nodeType === 1) {
|
||||
const currentNextSiblingTypes = currentNextSibling.dataset.type.split(" ")
|
||||
if (currentNextSiblingTypes.includes("code") || currentNextSiblingTypes.includes("tag") || currentNextSiblingTypes.includes("kbd")) {
|
||||
nextIsCTK = true;
|
||||
}
|
||||
} else if (currentNextSibling.textContent.startsWith(Constants.ZWSP)) {
|
||||
currentNextSibling.textContent = currentNextSibling.textContent.substring(1);
|
||||
}
|
||||
}
|
||||
if (currentNewNode) {
|
||||
if (previousIsCTK) {
|
||||
if (!currentNewNode.textContent.startsWith(Constants.ZWSP)) {
|
||||
currentNewNode.textContent = Constants.ZWSP + currentNewNode.textContent;
|
||||
}
|
||||
} else if (currentNewNode.textContent.startsWith(Constants.ZWSP)) {
|
||||
currentNewNode.textContent = currentNewNode.textContent.substring(1);
|
||||
}
|
||||
if (nextIsCTK) {
|
||||
if (!currentNextSibling.textContent.startsWith(Constants.ZWSP)) {
|
||||
currentNextSibling.textContent = Constants.ZWSP + currentNextSibling.textContent;
|
||||
}
|
||||
} else if (currentNewNode.textContent.endsWith(Constants.ZWSP)) {
|
||||
currentNewNode.textContent = currentNewNode.textContent.substring(0, currentNewNode.textContent.length - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.range.collapse(false);
|
||||
}
|
||||
|
|
|
@ -91,6 +91,7 @@ import {
|
|||
} from "../render/av/cell";
|
||||
import {openEmojiPanel, unicode2Emoji} from "../../emoji";
|
||||
import {openLink} from "../../editor/openLink";
|
||||
import {mathRender} from "../render/mathRender";
|
||||
|
||||
export class WYSIWYG {
|
||||
public lastHTMLs: { [key: string]: string } = {};
|
||||
|
@ -1443,6 +1444,7 @@ export class WYSIWYG {
|
|||
tempElement.append(range.extractContents());
|
||||
nodeElement.outerHTML = protyle.lute.SpinBlockDOM(nodeElement.outerHTML);
|
||||
nodeElement = protyle.wysiwyg.element.querySelector(`[data-node-id="${id}"]`) as HTMLElement;
|
||||
mathRender(nodeElement);
|
||||
focusByWbr(nodeElement, range);
|
||||
} else {
|
||||
const inlineMathElement = hasClosestByAttribute(range.commonAncestorContainer, "data-type", "inline-math");
|
||||
|
|
Loading…
Add table
Reference in a new issue