Skip to content

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

:art: fix https://github.com/siyuan-note/siyuan/issues/7658

Vanessaa70896998487
diff --git a/app/src/asset/anno.ts b/app/src/asset/anno.ts
index e06af11ed7..fec8605ace 100644
--- a/app/src/asset/anno.ts
+++ b/app/src/asset/anno.ts
@@ -2,7 +2,7 @@ import {fetchPost} from "../util/fetch";
import {setPosition} from "../util/setPosition";
import {hasClosestByAttribute, hasClosestByClassName} from "../protyle/util/hasClosest";
import * as dayjs from "dayjs";
-import {writeText} from "../protyle/util/compatibility";
+import {setStorageVal, writeText} from "../protyle/util/compatibility";
import {getAllModels} from "../layout/getAll";
/// #if !BROWSER
import {NativeImage} from "electron";
@@ -109,14 +109,22 @@ export const initAnno = (file: string, element: HTMLElement, annoId: string, pdf
documentSelf.onselect = null;
rectAnnoElement.classList.remove("toggled");
pdfConfig.mainContainer.classList.remove("rect-to-annotation");
- rectResizeElement.setAttribute("data-render", "true");
- const utilElement = element.querySelector(".pdf__util") as HTMLElement;
- utilElement.classList.remove("pdf__util--hide", "fn__none");
- const targetRect = rectResizeElement.getBoundingClientRect();
- setPosition(utilElement, targetRect.left,
- targetRect.top + targetRect.height + 4);
- rectElement = null;
- utilElement.classList.add("pdf__util--hide");
+
+ const coords = getHightlightCoordsByRect(pdf, window.siyuan.storage[Constants.LOCAL_PDFTHEME].annoColor || "var(--b3-pdf-background1)", rectResizeElement,
+ rectResizeElement.style.backgroundColor ? "text" : "border");
+ rectResizeElement.classList.add("fn__none");
+ if (coords) {
+ coords.forEach((item, index) => {
+ const newElement = showHighlight(item, pdf);
+ if (index === 0) {
+ rectElement = newElement;
+ copyAnno(`${pdf.appConfig.file.replace(location.origin, "").substr(1)}/${rectElement.getAttribute("data-node-id")}`,
+ pdf.appConfig.file.replace(location.origin, "").substr(8).replace(/-\d{14}-\w{7}.pdf$/, ""));
+ }
+ });
+ } else {
+ rectElement = null;
+ }
};
});
@@ -127,6 +135,8 @@ export const initAnno = (file: string, element: HTMLElement, annoId: string, pdf
const type = target.getAttribute("data-type");
if (target.classList.contains("color__square")) {
const color = target.style.backgroundColor;
+ window.siyuan.storage[Constants.LOCAL_PDFTHEME].annoColor = color;
+ setStorageVal(Constants.LOCAL_PDFTHEME, window.siyuan.storage[Constants.LOCAL_PDFTHEME]);
if (rectElement) {
const config = getConfig(pdf);
const annoItem = config[rectElement.getAttribute("data-node-id")];
@@ -144,14 +154,7 @@ export const initAnno = (file: string, element: HTMLElement, annoId: string, pdf
data: JSON.stringify(config),
});
} else {
- let coords;
- if (pdfConfig.mainContainer.lastElementChild.classList.contains("fn__none")) {
- coords = getHightlightCoordsByRange(pdf, color);
- } else {
- coords = getHightlightCoordsByRect(pdf, color, pdfConfig.mainContainer.lastElementChild,
- pdfConfig.mainContainer.lastElementChild.style.backgroundColor ? "text" : "border");
- pdfConfig.mainContainer.lastElementChild.classList.add("fn__none");
- }
+ const coords = getHightlightCoordsByRange(pdf, color);
if (coords) {
coords.forEach((item, index) => {
const newElement = showHighlight(item, pdf);
@@ -170,7 +173,6 @@ export const initAnno = (file: string, element: HTMLElement, annoId: string, pdf
break;
} else if (target.classList.contains("pdf__rect")) {
showToolbar(element, undefined, target);
- pdfConfig.mainContainer.lastElementChild.classList.add("fn__none");
event.preventDefault();
event.stopPropagation();
processed = true;
@@ -230,36 +232,18 @@ export const initAnno = (file: string, element: HTMLElement, annoId: string, pdf
}
setTimeout(() => {
- const rectIsResize = !pdfConfig.mainContainer.lastElementChild.classList.contains(
- "fn__none");
let isShow = false;
const selection = window.getSelection();
if (selection.rangeCount > 0) {
const range = selection.getRangeAt(0);
if (range.toString() !== "" &&
hasClosestByClassName(range.commonAncestorContainer, "pdfViewer")) {
- if (rectIsResize) {
- range.collapse(true);
- } else {
- showToolbar(element, range);
- isShow = true;
- }
+ showToolbar(element, range);
+ isShow = true;
}
}
-
if (!isShow) {
- if (rectIsResize) {
- if (!hasClosestByClassName(event.target as HTMLElement, "pdf__util") &&
- !hasClosestByClassName(event.target as HTMLElement, "pdf__resize") &&
- pdfConfig.mainContainer.lastElementChild.getAttribute(
- "data-render") !== "true") {
- hideToolbar(element);
- pdfConfig.mainContainer.lastElementChild.classList.add("fn__none");
- }
- pdfConfig.mainContainer.lastElementChild.removeAttribute("data-render");
- } else {
- hideToolbar(element);
- }
+ hideToolbar(element);
}
});
});
diff --git a/app/src/protyle/util/compatibility.ts b/app/src/protyle/util/compatibility.ts
index 44a4f33aad..1420b5739a 100644
--- a/app/src/protyle/util/compatibility.ts
+++ b/app/src/protyle/util/compatibility.ts
@@ -154,7 +154,7 @@ export const getLocalStorage = (cb: () => void) => {
rowTab: "",
layoutTab: 0
};
- defaultStorage[Constants.LOCAL_PDFTHEME] = {light: "light", dark: "dark"};
+ defaultStorage[Constants.LOCAL_PDFTHEME] = {light: "light", dark: "dark", annoColor: "var(--b3-pdf-background1)"};
defaultStorage[Constants.LOCAL_BAZAAR] = {
theme: "0",
template: "0",