Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/8554 调整划选范围

Vanessa4433ed22d71c
diff --git a/app/src/assets/scss/protyle/_protyle.scss b/app/src/assets/scss/protyle/_protyle.scss
index 0e33769937..0b28d352df 100644
--- a/app/src/assets/scss/protyle/_protyle.scss
+++ b/app/src/assets/scss/protyle/_protyle.scss
@@ -194,13 +194,19 @@
}
}
-.protyle-select {
+.protyle-select__container {
position: absolute;
- background-color: var(--b3-theme-primary-lightest);
+ inset: 0;
+ overflow: hidden;
z-index: 3; // 需大于 database header and footer
pointer-events: none; // 划选矩形不拦截鼠标事件,避免 elementFromPoint 命中自身
}
+.protyle-select {
+ position: absolute;
+ background-color: var(--b3-theme-primary-lightest);
+}
+
.protyle-breadcrumb {
display: flex;
padding: 0 8px;
diff --git a/app/src/protyle/ui/initUI.ts b/app/src/protyle/ui/initUI.ts
index f698307b48..28a03aa3ea 100644
--- a/app/src/protyle/ui/initUI.ts
+++ b/app/src/protyle/ui/initUI.ts
@@ -69,9 +69,12 @@ export const initUI = (protyle: IProtyle) => {
protyle.element.appendChild(protyle.hint.element);
+ const selectContainer = document.createElement("div");
+ selectContainer.className = "protyle-select__container";
protyle.selectElement = document.createElement("div");
protyle.selectElement.className = "protyle-select fn__none";
- protyle.element.appendChild(protyle.selectElement);
+ selectContainer.appendChild(protyle.selectElement);
+ protyle.element.appendChild(selectContainer);
protyle.element.appendChild(protyle.toolbar.element);
protyle.element.appendChild(protyle.toolbar.subElement);
diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts
index 6a537cd72b..2cb86b81f7 100644
--- a/app/src/protyle/wysiwyg/index.ts
+++ b/app/src/protyle/wysiwyg/index.ts
@@ -98,6 +98,7 @@ import {openLink} from "../../editor/openLink";
import {mathRender} from "../render/mathRender";
import {editAssetItem} from "../render/av/asset";
import {img3115} from "../../boot/compatibleVersion";
+import {dragOverScroll, stopScrollAnimation} from "../../boot/globalEvent/dragover";
import {globalClickHideMenu} from "../../boot/globalEvent/click";
import {hideTooltip} from "../../dialog/tooltip";
import {openGalleryItemMenu} from "../render/av/gallery/util";
@@ -1386,12 +1387,17 @@ export class WYSIWYG {
this.element.querySelectorAll("iframe").forEach(item => {
item.style.pointerEvents = "none";
});
- const needScroll = ["IMG", "VIDEO", "AUDIO"].includes(target.tagName) || target.classList.contains("img");
// 容器类元素判断(划选时 elementFromPoint 命中它们的边缘/空白需继续探测子块)
const isContainer = (el: Element) => el.classList.contains("protyle-wysiwyg") || el.classList.contains("list") ||
el.classList.contains("li") || el.classList.contains("sb") ||
el.classList.contains("callout") || el.classList.contains("bq");
+ let lastMoveEvent: MouseEvent;
+ const selectScrollEvent = () => lastMoveEvent && documentSelf.onmousemove?.(lastMoveEvent);
+ if (startsFromPadding) {
+ protyle.contentElement.addEventListener("scroll", selectScrollEvent);
+ }
documentSelf.onmousemove = (moveEvent: MouseEvent) => {
+ lastMoveEvent = moveEvent;
let moveTarget: boolean | HTMLElement = moveEvent.target as HTMLElement;
// table cell select
if (tableBlockElement &&
@@ -1475,13 +1481,15 @@ export class WYSIWYG {
}
// 在包含 img, video, audio 的元素上划选后无法上下滚动 https://ld246.com/article/1681778773806
// 在包含 img, video, audio 的元素上拖拽无法划选 https://github.com/siyuan-note/siyuan/issues/11763
- if (needScroll) {
- if (moveEvent.clientY < contentRect.top + Constants.SIZE_SCROLL_TB || moveEvent.clientY > contentRect.bottom - Constants.SIZE_SCROLL_TB) {
- protyle.contentElement.scroll({
- top: protyle.contentElement.scrollTop + (moveEvent.clientY < contentRect.top + Constants.SIZE_SCROLL_TB ? -Constants.SIZE_SCROLL_STEP : Constants.SIZE_SCROLL_STEP),
- behavior: "smooth"
- });
- }
+ if (startsFromPadding) {
+ dragOverScroll(moveEvent, contentRect, protyle.contentElement);
+ } else if ((moveEvent.target as HTMLElement).closest("img, video, audio, .img") &&
+ (moveEvent.clientY < contentRect.top + Constants.SIZE_SCROLL_TB ||
+ moveEvent.clientY > contentRect.bottom - Constants.SIZE_SCROLL_TB)) {
+ protyle.contentElement.scroll({
+ top: protyle.contentElement.scrollTop + (moveEvent.clientY < contentRect.top + Constants.SIZE_SCROLL_TB ? -Constants.SIZE_SCROLL_STEP : Constants.SIZE_SCROLL_STEP),
+ behavior: "smooth"
+ });
}
if (!nodeElement) {
return;
@@ -1623,6 +1631,10 @@ export class WYSIWYG {
};
documentSelf.onmouseup = (mouseUpEvent) => {
+ protyle.contentElement.removeEventListener("scroll", selectScrollEvent);
+ if (startsFromPadding) {
+ stopScrollAnimation();
+ }
documentSelf.onmousemove = null;
documentSelf.onmouseup = null;
documentSelf.ondragstart = null;