diff --git a/app/src/protyle/ui/initUI.ts b/app/src/protyle/ui/initUI.ts index c08f277e4..8920e6c85 100644 --- a/app/src/protyle/ui/initUI.ts +++ b/app/src/protyle/ui/initUI.ts @@ -115,11 +115,19 @@ export const initUI = (protyle: IProtyle) => { }, {passive: true}); protyle.contentElement.addEventListener("click", (event: MouseEvent & { target: HTMLElement }) => { // wysiwyg 元素下方点击无效果 https://github.com/siyuan-note/siyuan/issues/12009 - // 选中文本或块时,禁止添加空块 https://github.com/siyuan-note/siyuan/issues/13905 - if (protyle.disabled || window.getSelection().toString().length > 0 || event.target.querySelector(".protyle-wysiwyg--select") || + if (protyle.disabled || + // 选中块时,禁止添加空块 https://github.com/siyuan-note/siyuan/issues/13905 + protyle.contentElement.querySelector(".protyle-wysiwyg--select") || (!event.target.classList.contains("protyle-content") && !event.target.classList.contains("protyle-wysiwyg"))) { return; } + // 选中文本禁止添加空块 https://github.com/siyuan-note/siyuan/issues/13905 + if (window.getSelection().rangeCount > 0) { + const currentRange = window.getSelection().getRangeAt(0); + if (currentRange.toString() !== "" && protyle.wysiwyg.element.contains(currentRange.startContainer)) { + return; + } + } const lastRect = protyle.wysiwyg.element.lastElementChild.getBoundingClientRect(); const range = document.createRange(); if (event.y > lastRect.bottom) {