Skip to content

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

:sparkles: Show image position and total in preview https://github.com/siyuan-note/siyuan/issues/20796

Daniel6b3cbb44185e
diff --git a/app/src/protyle/preview/image.livePhoto.test.ts b/app/src/protyle/preview/image.livePhoto.test.ts
index caa66120be..145d65d80d 100644
--- a/app/src/protyle/preview/image.livePhoto.test.ts
+++ b/app/src/protyle/preview/image.livePhoto.test.ts
@@ -8,7 +8,7 @@ import {test} from "node:test";
import {promisify} from "node:util";
import {transpileModule, ModuleKind, ScriptTarget} from "typescript";
-test("image gallery releases playing and converting Live Photos on navigation and slideshow", async () => {
+test("image gallery counts entries and releases Live Photos on navigation and slideshow", async () => {
const root = realpathSync(tmpdir());
const temporary = mkdtempSync(path.join(root, "siyuan-live-photo-gallery-"));
const server = createServer((request, response) => {
@@ -59,6 +59,12 @@ test("image gallery releases playing and converting Live Photos on navigation an
exports.previewDocImage(image,"document","assets/second.mov");
await wait(()=>window.siyuan.viewer?.viewed);
const viewer=window.siyuan.viewer;
+ const checkCount = expected => {
+ if (!viewer.title.textContent.startsWith(expected + " ")) {
+ throw new Error("gallery count mismatch: " + viewer.title.textContent);
+ }
+ };
+ checkCount("2/3");
const button=viewer.toolbar.querySelector(".viewer-live-photo");
if (!button || button.classList.contains("fn__none")) {throw new Error("Live Photo action missing");}
const icon=button.querySelector("use");
@@ -68,6 +74,7 @@ test("image gallery releases playing and converting Live Photos on navigation an
button.click();
viewer.view(0);
await wait(()=>viewer.index===0 && viewer.viewed);
+ checkCount("1/3");
button.dispatchEvent(new KeyboardEvent("keydown",{key:"Enter",bubbles:true}));
viewer.options.autoplay=false;
viewer.play();
@@ -80,6 +87,7 @@ test("image gallery releases playing and converting Live Photos on navigation an
viewer.stop();
viewer.view(2);
await wait(()=>viewer.index===2 && viewer.viewed);
+ checkCount("3/3");
const hidden=button.classList.contains("fn__none");
viewer.destroy();
return {starts,stopped,hidden,closed};
diff --git a/app/src/protyle/preview/image.test.ts b/app/src/protyle/preview/image.test.ts
index ab5176078f..f4562dc49a 100644
--- a/app/src/protyle/preview/image.test.ts
+++ b/app/src/protyle/preview/image.test.ts
@@ -31,7 +31,7 @@ test("image preview initializes its toolbar when ready is dispatched on the sour
const copied: string[] = [];
const copiedFiles: string[] = [];
let supportsFiles = true;
- const sourceElement = new EventTarget();
+ const sourceElement = Object.assign(new EventTarget(), {childElementCount: 2});
class TestViewer {
public viewed = true;
public viewer = {
@@ -46,8 +46,9 @@ test("image preview initializes its toolbar when ready is dispatched on the sour
};
constructor(element: EventTarget, public options: {
+ title: [number, (image: {alt: string}, data: {naturalWidth: number, naturalHeight: number}) => string],
ready: EventListener,
- view: () => void,
+ view: (event?: {detail: {index: number}}) => void,
viewed: () => void,
toolbar: {copy: () => void, copyFile: () => void},
}) {
@@ -88,6 +89,13 @@ test("image preview initializes its toolbar when ready is dispatched on the sour
exports.previewImages(["blob:first", "blob:second"]);
await Promise.resolve();
const instance = previewWindow.siyuan.viewer;
+ const title = () => instance.options.title[1]({alt: "photo.png"}, {naturalWidth: 640, naturalHeight: 480});
+ assert.equal(title(), "1/2 photo [640 × 480]");
+ instance.options.view({detail: {index: 1}});
+ assert.equal(title(), "2/2 photo [640 × 480]");
+ instance.options.view({detail: {index: 0}});
+ sourceElement.childElementCount = 1;
+ assert.equal(title(), "1/1 photo [640 × 480]");
assert.match(buttons.get(".viewer-copy").innerHTML, /#iconImage/);
assert.match(buttons.get(".viewer-copy-file").innerHTML, /#iconFile/);
assert.equal(buttons.get(".viewer-copy").attributes.get("aria-label"), "Copy as PNG");
diff --git a/app/src/protyle/preview/image.ts b/app/src/protyle/preview/image.ts
index 2f58939257..61cc098583 100644
--- a/app/src/protyle/preview/image.ts
+++ b/app/src/protyle/preview/image.ts
@@ -65,7 +65,7 @@ export const previewImages = (srcList: Array<string | {src: string, video?: stri
name = image.src.substring(image.src.lastIndexOf("/") + 1);
}
name = name.substring(0, name.lastIndexOf(".")).replace(/-\d{14}-\w{7}$/, "");
- return `${name} [${imageData.naturalWidth} × ${imageData.naturalHeight}]`;
+ return `${currentIndex + 1}/${imagesElement.childElementCount} ${name} [${imageData.naturalWidth} × ${imageData.naturalHeight}]`;
}],
button: false,
magnifier: false,