Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: fix https://github.com/siyuan-note/siyuan/issues/6796

Vanessab803b356ce4e
diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts
index e3a580a89d..337bd64cdd 100644
--- a/app/src/protyle/toolbar/index.ts
+++ b/app/src/protyle/toolbar/index.ts
@@ -563,7 +563,8 @@ export class Toolbar {
this.range.insertNode(currentNewNode);
// https://github.com/siyuan-note/siyuan/issues/6155
if (currentNewNode.nodeType !== 3 && ["code", "tag", "kbd"].includes(type)) {
- if (!hasPreviousSibling(currentNewNode)) {
+ const previousSibling = hasPreviousSibling(currentNewNode)
+ if (!previousSibling || previousSibling.textContent.endsWith("\n")) {
currentNewNode.before(document.createTextNode(Constants.ZWSP));
}
if (!currentNewNode.textContent.startsWith(Constants.ZWSP)) {
diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts
index d95c4457fd..a7d4e44609 100644
--- a/app/src/protyle/wysiwyg/keydown.ts
+++ b/app/src/protyle/wysiwyg/keydown.ts
@@ -686,8 +686,18 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => {
event.preventDefault();
return;
}
- // https://github.com/siyuan-note/siyuan/issues/5547
+ // https://github.com/siyuan-note/siyuan/issues/6796
const previousSibling = hasPreviousSibling(range.startContainer) as HTMLElement;
+ if (range.toString() === "" && event.key === "Backspace" &&
+ range.startOffset === range.startContainer.textContent.length &&
+ range.startContainer.textContent.endsWith("\n"+Constants.ZWSP)) {
+ range.setStart(range.startContainer, range.startOffset - 1);
+ range.collapse(true);
+ event.stopPropagation();
+ event.preventDefault();
+ return;
+ }
+ // https://github.com/siyuan-note/siyuan/issues/5547
if (range.startOffset === 1 && range.startContainer.textContent === Constants.ZWSP &&
previousSibling && previousSibling.nodeType !== 3 &&
event.key === "Backspace" // https://github.com/siyuan-note/siyuan/issues/6786