From 3f0ec1630af29c14abc380ea3500d0da895cbec4 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Tue, 4 Feb 2025 17:10:58 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/pull/13975 --- app/src/protyle/ui/initUI.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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) {