From d4f94b9b1b5eacc7254a2393bc5af3dbe6e9c9e6 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Wed, 28 Aug 2024 17:30:30 +0800 Subject: [PATCH] :bug: fix https://github.com/siyuan-note/siyuan/issues/12317 --- app/src/protyle/util/paste.ts | 7 ------- app/src/protyle/wysiwyg/index.ts | 6 ++++++ app/src/protyle/wysiwyg/keydown.ts | 6 +----- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/app/src/protyle/util/paste.ts b/app/src/protyle/util/paste.ts index 307fd540b..1b4eab297 100644 --- a/app/src/protyle/util/paste.ts +++ b/app/src/protyle/util/paste.ts @@ -343,13 +343,6 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven const range = getEditorRange(protyle.wysiwyg.element); if (nodeElement.getAttribute("data-type") === "NodeCodeBlock" || protyle.toolbar.getCurrentType(range).includes("code")) { - // 粘贴在代码位置 - // https://github.com/siyuan-note/siyuan/issues/9142 - // https://github.com/siyuan-note/siyuan/issues/9323 - // 需排除行内代码 https://github.com/siyuan-note/siyuan/issues/9369 - if (nodeElement.querySelector(".protyle-action")?.contains(range.startContainer)) { - range.setStart(nodeElement.querySelector(".hljs").firstChild, 0); - } insertHTML(textPlain, protyle); return; } else if (siyuanHTML) { diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index da6eb6c62..fbfe55303 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/app/src/protyle/wysiwyg/index.ts @@ -2080,6 +2080,12 @@ export class WYSIWYG { protyle.breadcrumb.render(protyle, false, hasClosestBlock(event.target)); } const range = getEditorRange(this.element); + // https://github.com/siyuan-note/siyuan/issues/12317 + if (range.startContainer.nodeType !== 3 && + (range.startContainer as Element).classList.contains("protyle-action") && + range.startContainer.parentElement.classList.contains("code-block")) { + setFirstNodeRange(range.startContainer.parentElement.querySelector(".hljs").lastElementChild, range); + } // 需放在嵌入块之前,否则嵌入块内的引用、链接、pdf 双链无法点击打开 https://ld246.com/article/1630479789513 const aElement = hasClosestByAttribute(event.target, "data-type", "a") || hasClosestByClassName(event.target, "av__celltext--url"); // 数据库中资源文件、链接、电话、邮箱单元格 diff --git a/app/src/protyle/wysiwyg/keydown.ts b/app/src/protyle/wysiwyg/keydown.ts index f711c21d3..f8a490690 100644 --- a/app/src/protyle/wysiwyg/keydown.ts +++ b/app/src/protyle/wysiwyg/keydown.ts @@ -1570,10 +1570,6 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { const tabSpace = window.siyuan.config.editor.codeTabSpaces === 0 ? "\t" : "".padStart(window.siyuan.config.editor.codeTabSpaces, " "); if (nodeElement.getAttribute("data-type") === "NodeCodeBlock" && selectText !== "") { const wbrElement = document.createElement("wbr"); - // https://github.com/siyuan-note/siyuan/issues/8911 - if (range.startContainer.nodeType !== 3 && (range.startContainer as Element).classList.contains("protyle-action")) { - range.setStart(nodeElement.querySelector(".hljs").firstChild, 0); - } range.insertNode(wbrElement); range.setStartAfter(wbrElement); const oldHTML = nodeElement.outerHTML; @@ -1601,7 +1597,7 @@ export const keydown = (protyle: IProtyle, editorElement: HTMLElement) => { }).value + "
"); range.setStart(wbrElement.nextSibling, 0); const brElement = wbrElement.parentElement.querySelector("br"); - range.setEnd(brElement.previousSibling, brElement.previousSibling.textContent.length); + setLastNodeRange(brElement.previousSibling as Element, range, false); brElement.remove(); updateTransaction(protyle, nodeElement.getAttribute("data-node-id"), nodeElement.outerHTML, oldHTML); wbrElement.remove();