|
@@ -629,10 +629,10 @@ export class Toolbar {
|
|
i--;
|
|
i--;
|
|
} else {
|
|
} else {
|
|
this.range.insertNode(currentNewNode);
|
|
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));
|
|
currentNewNode.before(document.createTextNode(Constants.ZWSP));
|
|
}
|
|
}
|
|
if (!currentNewNode.textContent.startsWith(Constants.ZWSP)) {
|
|
if (!currentNewNode.textContent.startsWith(Constants.ZWSP)) {
|
|
@@ -647,6 +647,47 @@ export class Toolbar {
|
|
) {
|
|
) {
|
|
currentNewNode.after(document.createTextNode(Constants.ZWSP));
|
|
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);
|
|
this.range.collapse(false);
|
|
}
|
|
}
|