From 7f8307dd7276f0cbbb2f7db2986061794656198e Mon Sep 17 00:00:00 2001 From: Vanessa Date: Tue, 11 Oct 2022 21:49:33 +0800 Subject: [PATCH] :bug: fix https://github.com/siyuan-note/siyuan/issues/6155 --- app/src/protyle/toolbar/index.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts index 3348cc182..c2cc01185 100644 --- a/app/src/protyle/toolbar/index.ts +++ b/app/src/protyle/toolbar/index.ts @@ -537,6 +537,24 @@ 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)) { + if (!hasPreviousSibling(currentNewNode)) { + currentNewNode.before(document.createTextNode(Constants.ZWSP)); + } + if (!currentNewNode.textContent.startsWith(Constants.ZWSP)) { + currentNewNode.textContent = Constants.ZWSP + currentNewNode.textContent; + } + const currentNextSibling = hasNextSibling(currentNewNode); + if (!currentNextSibling || + (currentNextSibling && ( + currentNextSibling.nodeType !== 3 || + (currentNextSibling.nodeType === 3 && !currentNextSibling.textContent.startsWith(Constants.ZWSP))) + ) + ) { + currentNewNode.after(document.createTextNode(Constants.ZWSP)); + } + } this.range.collapse(false); } }