diff --git a/app/src/boot/globalEvent/keydown.ts b/app/src/boot/globalEvent/keydown.ts index fe9acb3ef..fec1306fc 100644 --- a/app/src/boot/globalEvent/keydown.ts +++ b/app/src/boot/globalEvent/keydown.ts @@ -507,10 +507,10 @@ const editKeydown = (app: App, event: KeyboardEvent) => { if (!isFileFocus && matchHotKey(window.siyuan.config.keymap.editor.general.copyBlockRef.custom, event)) { event.preventDefault(); event.stopPropagation(); - if (hasClosestByClassName(range.startContainer, "protyle-title")) { + if (hasClosestByClassName(range?.startContainer, "protyle-title")) { copyTextByType([protyle.block.rootID], "ref"); } else { - const nodeElement = hasClosestBlock(range.startContainer); + const nodeElement = hasClosestBlock(range?.startContainer); if (!nodeElement) { return false; } @@ -519,16 +519,17 @@ const editKeydown = (app: App, event: KeyboardEvent) => { copyPNGByLink(selectImgElement.querySelector("img").getAttribute("src")); return true; } + const selectBlocks = protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select"); + if (selectBlocks.length !== 0) { + copyTextByType(Array.from(selectBlocks).map(item => item.getAttribute("data-node-id")), "ref"); + return true; + } if (range.toString() !== "") { getContentByInlineHTML(range, (content) => { writeText(`((${nodeElement.getAttribute("data-node-id")} "${content.trim()}"))`); }); } else { - const ids = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select")).map(item => item.getAttribute("data-node-id")); - if (ids.length === 0) { - ids.push(nodeElement.getAttribute("data-node-id")); - } - copyTextByType(ids, "ref"); + copyTextByType([nodeElement.getAttribute("data-node-id")], "ref"); } } return true; diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts index 932b921d2..38ed4fdc3 100644 --- a/app/src/protyle/wysiwyg/index.ts +++ b/app/src/protyle/wysiwyg/index.ts @@ -2157,9 +2157,8 @@ export class WYSIWYG { event.stopPropagation(); } - // https://github.com/siyuan-note/siyuan/issues/8918 - if ((event.key === "ArrowLeft" || event.key === "ArrowRight" || - event.key === "Alt" || event.key === "Shift") && // 选中后 alt+shift+arrowRight 会导致光标和选中块不一致 + // 按下方向键后块高亮跟随光标移动 https://github.com/siyuan-note/siyuan/issues/8918 + if ((event.key === "ArrowLeft" || event.key === "ArrowRight") && nodeElement && !nodeElement.classList.contains("protyle-wysiwyg--select")) { const selectElements = Array.from(protyle.wysiwyg.element.querySelectorAll(".protyle-wysiwyg--select")); let containRange = false;