Skip to content

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

:lipstick: Show touch image resize handles after selection https://github.com/siyuan-note/siyuan/issues/20708

Danielaed3d2cd67ea
diff --git a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-h361q1i/20200924093441-ft2rhps.sy b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-h361q1i/20200924093441-ft2rhps.sy
index 46ebd39460..41efb4eecf 100644
--- a/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-h361q1i/20200924093441-ft2rhps.sy
+++ b/app/guide/20210808180117-6v0mkxr/20200923234011-ieuun1p/20210808180303-h361q1i/20200924093441-ft2rhps.sy
@@ -8,7 +8,7 @@
"title": "Formatting elements",
"title-img": "background-color:#269;background-image: linear-gradient(white 2px, transparent 2px),linear-gradient(90deg, white 2px, transparent 2px),linear-gradient(rgba(255,255,255,.3) 1px, transparent 1px),linear-gradient(90deg, rgba(255,255,255,.3) 1px, transparent 1px);background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;background-position:-2px -2px, -2px -2px, -1px -1px, -1px -1px;",
"type": "doc",
- "updated": "20261019142953"
+ "updated": "20261019194432"
},
"Children": [
{
@@ -17,7 +17,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20210104091509-sg4pt12",
- "updated": "20261018210230"
+ "updated": "20261019194432"
},
"Children": [
{
@@ -32,7 +32,7 @@
"ListData": {},
"Properties": {
"id": "20210104091509-8csaq4j",
- "updated": "20261018210230"
+ "updated": "20261019194432"
},
"Children": [
{
@@ -105,7 +105,7 @@
},
"Properties": {
"id": "20220916200111-8pnrqr2",
- "updated": "20261018210230"
+ "updated": "20261019194432"
},
"Children": [
{
@@ -127,12 +127,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20210604225055-4pq8g38",
- "updated": "20261018210230"
+ "updated": "20261019194432"
},
"Children": [
{
"Type": "NodeText",
- "Data": "Paste or drag images to upload them. Hover over an image to reveal the small handles outside its border, then drag the right, bottom, or bottom-right handle to resize it proportionally. On touchscreens, drag a handle directly"
+ "Data": "Paste or drag images to upload them. Hover over an image to reveal the small handles outside its border, then drag the right, bottom, or bottom-right handle to resize it proportionally. On touchscreens, tap an image to reveal its handles, then drag a handle"
}
]
},
diff --git a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-abz7w6k/20200825162036-4dx365o.sy b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-abz7w6k/20200825162036-4dx365o.sy
index 68c4ee3178..2aadf4fd3f 100644
--- a/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-abz7w6k/20200825162036-4dx365o.sy
+++ b/app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-abz7w6k/20200825162036-4dx365o.sy
@@ -8,7 +8,7 @@
"title": "排版元素",
"title-img": "background-color: hsl(2, 57%, 40%);background-image: repeating-linear-gradient(transparent, transparent 50px, rgba(0,0,0,.4) 50px, rgba(0,0,0,.4) 53px, transparent 53px, transparent 63px, rgba(0,0,0,.4) 63px, rgba(0,0,0,.4) 66px, transparent 66px, transparent 116px, rgba(0,0,0,.5) 116px, rgba(0,0,0,.5) 166px, rgba(255,255,255,.2) 166px, rgba(255,255,255,.2) 169px, rgba(0,0,0,.5) 169px, rgba(0,0,0,.5) 179px, rgba(255,255,255,.2) 179px, rgba(255,255,255,.2) 182px, rgba(0,0,0,.5) 182px, rgba(0,0,0,.5) 232px, transparent 232px),repeating-linear-gradient(270deg, transparent, transparent 50px, rgba(0,0,0,.4) 50px, rgba(0,0,0,.4) 53px, transparent 53px, transparent 63px, rgba(0,0,0,.4) 63px, rgba(0,0,0,.4) 66px, transparent 66px, transparent 116px, rgba(0,0,0,.5) 116px, rgba(0,0,0,.5) 166px, rgba(255,255,255,.2) 166px, rgba(255,255,255,.2) 169px, rgba(0,0,0,.5) 169px, rgba(0,0,0,.5) 179px, rgba(255,255,255,.2) 179px, rgba(255,255,255,.2) 182px, rgba(0,0,0,.5) 182px, rgba(0,0,0,.5) 232px, transparent 232px),repeating-linear-gradient(125deg, transparent, transparent 2px, rgba(0,0,0,.2) 2px, rgba(0,0,0,.2) 3px, transparent 3px, transparent 5px, rgba(0,0,0,.2) 5px);",
"type": "doc",
- "updated": "20261019142953"
+ "updated": "20261019194453"
},
"Children": [
{
@@ -17,7 +17,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20210604182832-nm3hapx",
- "updated": "20261018210230"
+ "updated": "20261019194453"
},
"Children": [
{
@@ -32,7 +32,7 @@
"ListData": {},
"Properties": {
"id": "20210104091228-ttcj9nm",
- "updated": "20261018210230"
+ "updated": "20261019194453"
},
"Children": [
{
@@ -105,7 +105,7 @@
},
"Properties": {
"id": "20220916195046-bdzv6fy",
- "updated": "20261018210230"
+ "updated": "20261019194453"
},
"Children": [
{
@@ -127,12 +127,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20210604222221-9zkgkky",
- "updated": "20261018210230"
+ "updated": "20261019194453"
},
"Children": [
{
"Type": "NodeText",
- "Data": "可通过复制粘贴或拖拽来上传图片。将鼠标移到图片上可显示边框外的小手柄,拖动右侧、底部或右下角的手柄可等比调整大小;触屏可直接拖动手柄"
+ "Data": "可通过复制粘贴或拖拽来上传图片。将鼠标移到图片上可显示边框外的小手柄,拖动右侧、底部或右下角的手柄可等比调整大小;触屏上先点击图片显示手柄,再拖动手柄"
}
]
},
diff --git a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226120854-dr1jfx2/20211226121319-emrk2yy.sy b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226120854-dr1jfx2/20211226121319-emrk2yy.sy
index 8a0ff1596e..f7fd5b8adc 100644
--- a/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226120854-dr1jfx2/20211226121319-emrk2yy.sy
+++ b/app/guide/20211226090932-5lcq56f/20211226115423-d5z1joq/20211226120854-dr1jfx2/20211226121319-emrk2yy.sy
@@ -8,7 +8,7 @@
"title": "排版元素",
"title-img": "background-color: hsl(2, 57%, 40%);background-image: repeating-linear-gradient(transparent, transparent 50px, rgba(0,0,0,.4) 50px, rgba(0,0,0,.4) 53px, transparent 53px, transparent 63px, rgba(0,0,0,.4) 63px, rgba(0,0,0,.4) 66px, transparent 66px, transparent 116px, rgba(0,0,0,.5) 116px, rgba(0,0,0,.5) 166px, rgba(255,255,255,.2) 166px, rgba(255,255,255,.2) 169px, rgba(0,0,0,.5) 169px, rgba(0,0,0,.5) 179px, rgba(255,255,255,.2) 179px, rgba(255,255,255,.2) 182px, rgba(0,0,0,.5) 182px, rgba(0,0,0,.5) 232px, transparent 232px),repeating-linear-gradient(270deg, transparent, transparent 50px, rgba(0,0,0,.4) 50px, rgba(0,0,0,.4) 53px, transparent 53px, transparent 63px, rgba(0,0,0,.4) 63px, rgba(0,0,0,.4) 66px, transparent 66px, transparent 116px, rgba(0,0,0,.5) 116px, rgba(0,0,0,.5) 166px, rgba(255,255,255,.2) 166px, rgba(255,255,255,.2) 169px, rgba(0,0,0,.5) 169px, rgba(0,0,0,.5) 179px, rgba(255,255,255,.2) 179px, rgba(255,255,255,.2) 182px, rgba(0,0,0,.5) 182px, rgba(0,0,0,.5) 232px, transparent 232px),repeating-linear-gradient(125deg, transparent, transparent 2px, rgba(0,0,0,.2) 2px, rgba(0,0,0,.2) 3px, transparent 3px, transparent 5px, rgba(0,0,0,.2) 5px);",
"type": "doc",
- "updated": "20261019142953"
+ "updated": "20261019194453"
},
"Children": [
{
@@ -17,7 +17,7 @@
"HeadingLevel": 2,
"Properties": {
"id": "20211226122008-i45akvs",
- "updated": "20261018210230"
+ "updated": "20261019194453"
},
"Children": [
{
@@ -32,7 +32,7 @@
"ListData": {},
"Properties": {
"id": "20211226122008-1e014nh",
- "updated": "20261018210230"
+ "updated": "20261019194453"
},
"Children": [
{
@@ -105,7 +105,7 @@
},
"Properties": {
"id": "20220916195409-g57vfyf",
- "updated": "20261018210230"
+ "updated": "20261019194453"
},
"Children": [
{
@@ -127,12 +127,12 @@
"Type": "NodeParagraph",
"Properties": {
"id": "20211226122008-pei037e",
- "updated": "20261018210230"
+ "updated": "20261019194453"
},
"Children": [
{
"Type": "NodeText",
- "Data": "可透過複製貼上或拖曳來上傳圖片。將滑鼠移到圖片上可顯示邊框外的小把手,拖曳右側、底部或右下角的把手可等比例調整大小;觸控螢幕可直接拖曳把手"
+ "Data": "可透過複製貼上或拖曳來上傳圖片。將滑鼠移到圖片上可顯示邊框外的小把手,拖曳右側、底部或右下角的把手可等比例調整大小;在觸控螢幕上先點選圖片顯示把手,再拖曳把手"
}
]
},
diff --git a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-hnu6o79/20240530101000-3qhz7br.sy b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-hnu6o79/20240530101000-3qhz7br.sy
index 361d3ce107..32f9bc4705 100644
--- a/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-hnu6o79/20240530101000-3qhz7br.sy
+++ b/app/guide/20240530133126-axarxgx/20240530101000-4qitucx/20240530101000-hnu6o79/20240530101000-3qhz7br.sy
@@ -9,7 +9,7 @@
"title": "書式要素",
"title-img": "background-color:#269;background-image: linear-gradient(white 2px, transparent 2px),linear-gradient(90deg, white 2px, transparent 2px),linear-gradient(rgba(255,255,255,.3) 1px, transparent 1px),linear-gradient(90deg, rgba(255,255,255,.3) 1px, transparent 1px);background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;background-position:-2px -2px, -2px -2px, -1px -1px, -1px -1px;",
"type": "doc",
- "updated": "20261019142953"
+ "updated": "20261019194453"
},
"Children": [
{
@@ -19,7 +19,7 @@
"Properties": {
"ID": "20240530101000-tfcp9du",
"id": "20240530101000-e1tndfu",
- "updated": "20261018210230"
+ "updated": "20261019194453"
},
"Children": [
{
@@ -35,7 +35,7 @@
"Properties": {
"ID": "20240530101000-8o1a9my",
"id": "20240530101000-wlqefeq",
- "updated": "20261018210230"
+ "updated": "20261019194453"
},
"Children": [
{
@@ -113,7 +113,7 @@
"Properties": {
"ID": "20240530101000-gjgldj9",
"id": "20240530101000-gm1p50s",
- "updated": "20261018210230"
+ "updated": "20261019194453"
},
"Children": [
{
@@ -137,12 +137,12 @@
"Properties": {
"ID": "20240530101000-h8nud0n",
"id": "20240530101000-r0imp45",
- "updated": "20261018210230"
+ "updated": "20261019194453"
},
"Children": [
{
"Type": "NodeText",
- "Data": "コピー&ペースト、またはドラッグ&ドロップで画像をアップロードできます。画像にマウスを合わせると枠の外側に小さなハンドルが表示され、右側、下側、右下のハンドルをドラッグして縦横比を保ちながらサイズを変更できます。タッチスクリーンではハンドルを直接ドラッグできます"
+ "Data": "コピー&ペースト、またはドラッグ&ドロップで画像をアップロードできます。画像にマウスを合わせると枠の外側に小さなハンドルが表示され、右側、下側、右下のハンドルをドラッグして縦横比を保ちながらサイズを変更できます。タッチスクリーンでは画像をタップしてハンドルを表示してから、ハンドルをドラッグします"
}
]
},
diff --git a/app/src/assets/scss/protyle/_wysiwyg.scss b/app/src/assets/scss/protyle/_wysiwyg.scss
index cf08f19f95..09c34a0bd4 100644
--- a/app/src/assets/scss/protyle/_wysiwyg.scss
+++ b/app/src/assets/scss/protyle/_wysiwyg.scss
@@ -990,6 +990,13 @@ body[data-format-painter] .protyle-wysiwyg[data-readonly="false"] {
}
}
+@media (hover: none) and (pointer: coarse) {
+ .protyle-wysiwyg .img:not(.img--select):not(.img--drag) .protyle-block-resize {
+ visibility: hidden;
+ pointer-events: none;
+ }
+}
+
.protyle-format-painter__cursor {
position: fixed;
z-index: 9;
diff --git a/app/src/protyle/render/iframeResize.test.ts b/app/src/protyle/render/iframeResize.test.ts
index 61af5dc250..bb8159892e 100644
--- a/app/src/protyle/render/iframeResize.test.ts
+++ b/app/src/protyle/render/iframeResize.test.ts
@@ -652,7 +652,7 @@ test("external resize handles preserve source, independent axes, historical dime
const hintFile = createSourceFile("hint.ts", readFileSync("src/protyle/hint/index.ts", "utf8"), ScriptTarget.ES2021, true);
const hintDeclaration = hintFile.statements.find(node => isClassDeclaration(node) && node.name.text === "Hint");
assert.ok(hintDeclaration && isClassDeclaration(hintDeclaration));
- const hintMethods = hintDeclaration.members.filter(member => ["fill", "fillCommand", "consumeRefBracketClose"].includes(member.name?.getText(hintFile)))
+ const hintMethods = hintDeclaration.members.filter(member => ["fill", "fillCommand", "consumeRefBracketClose", "openNewTableCell"].includes(member.name?.getText(hintFile)))
.map(member => member.getText(hintFile)).join("\n");
const hintSource = transpileModule(`class Hint { ${hintMethods} }`, {compilerOptions: {target: ScriptTarget.ES2021}}).outputText;
const menuFile = createSourceFile("menu.ts", readFileSync("src/menus/protyle.ts", "utf8"), ScriptTarget.ES2021, true);
diff --git a/app/src/protyle/render/imageResize.test.ts b/app/src/protyle/render/imageResize.test.ts
index b11456c4eb..e919f5aa29 100644
--- a/app/src/protyle/render/imageResize.test.ts
+++ b/app/src/protyle/render/imageResize.test.ts
@@ -9,8 +9,10 @@ import {compileString} from "sass";
import {createSourceFile, isIfStatement, ModuleKind, ScriptTarget, transpileModule} from "typescript";
const browserCases = async (source: string, resizeSource: string, luteSource: string, css: string,
- bridgeSource: string, coreSource: string) => {
+ bridgeSource: string, coreSource: string, selectionSource: string, touchMode: boolean) => {
const check: typeof assert = require("node:assert/strict");
+ check.equal(matchMedia("(hover: none) and (pointer: coarse)").matches, touchMode,
+ "the test exercises the requested input mode");
new Function(luteSource)();
const lute = Lute.New();
const api = new Function(source + "\nreturn {bindImageResize, getImageResizeWidth};")() as typeof import("./imageResize");
@@ -54,6 +56,22 @@ const browserCases = async (source: string, resizeSource: string, luteSource: st
return image;
};
const updates: {before: string, after: string}[] = [];
+ const selection = new Function("clearSelect", "hideElements", "hasClosestByAttribute", "hasClosestByClassName",
+ selectionSource)(
+ (types: string[], element: HTMLElement) => {
+ if (types.includes("img")) {
+ element.querySelectorAll(".img--select").forEach(item => item.classList.remove("img--select"));
+ }
+ }, () => {},
+ (element: HTMLElement, name: string, value: string) => element.closest(`[${name}="${value}"]`),
+ (element: HTMLElement, name: string) => element.closest(`.${name}`),
+ );
+ root.addEventListener("mousedown", event => selection.clear(event.target, root));
+ root.addEventListener("click", event => selection.select(event));
+ const tap = (element: HTMLElement) => {
+ element.dispatchEvent(new MouseEvent("mousedown", {bubbles: true}));
+ element.dispatchEvent(new MouseEvent("click", {bubbles: true}));
+ };
const start = new Function("getImageResizeWidth", "protyle", "target", "nodeElement", "event", "documentSelf",
"mostRight", "mostBottom", "y", "focusBlock", "updateTransaction", "img3115", resizeSource);
const begin = (image: HTMLImageElement, axis: string, event: MouseEvent) => {
@@ -70,6 +88,7 @@ const browserCases = async (source: string, resizeSource: string, luteSource: st
for (const legacy of [false, true]) {
for (const axis of ["width", "height", "both"]) {
const image = await create(legacy);
+ tap(image);
const block = root.firstElementChild as HTMLElement;
const before = block.outerHTML;
const frame = image.parentElement.querySelector<HTMLElement>(".protyle-image-resize");
@@ -140,6 +159,7 @@ const browserCases = async (source: string, resizeSource: string, luteSource: st
bridge.initTouchDragBridge();
for (const axis of ["width", "height", "both"]) {
const image = await create();
+ tap(image);
const width = image.clientWidth;
const handle = image.parentElement.querySelector<HTMLElement>(`.protyle-block-resize[data-resize-axis="${axis}"]`);
handle.addEventListener("mousedown", event => begin(image, axis, event));
@@ -150,18 +170,31 @@ const browserCases = async (source: string, resizeSource: string, luteSource: st
const touch = new Touch({identifier: 1, target: handle, clientX: rect.left + rect.width / 2 + (moved ? dx : 0),
clientY: rect.top + rect.height / 2 + (moved ? dy : 0), radiusX: 1, radiusY: 1});
const event = new TouchEvent(type, {bubbles: true, cancelable: true,
- touches: type === "touchend" ? [] : [touch], changedTouches: [touch]});
+ touches: type === "touchend" || type === "touchcancel" ? [] : [touch], changedTouches: [touch]});
handle.dispatchEvent(event);
return event;
};
updates.length = 0;
dispatch("touchstart", false);
+ check.equal(image.closest(".img").classList.contains("img--select"), true,
+ "pressing a resize handle preserves image selection");
+ check.equal(getComputedStyle(handle).visibility, "visible", "the active handle remains visible");
check.equal(dispatch("touchmove", true).defaultPrevented, true);
dispatch("touchend", true);
check.equal(image.clientWidth, width + 20, `${axis} touch drag resizes the image`);
check.equal(image.clientHeight * 2, image.clientWidth);
check.equal(updates.length, 1);
check.equal(document.onmousemove, null);
+ check.equal(getComputedStyle(handle).visibility, "visible", "handles remain available for another drag");
+ dispatch("touchstart", false);
+ dispatch("touchmove", true);
+ dispatch("touchend", true);
+ check.equal(image.clientWidth, width + 40, `${axis} supports another drag without reselecting the image`);
+ dispatch("touchstart", false);
+ dispatch("touchcancel", false);
+ check.equal(document.onmousemove, null, "cancelled resizing releases the touch bridge");
+ check.equal(handle.classList.contains("touch-resize-active"), false);
+ check.equal(getComputedStyle(handle).visibility, "visible", "cancelling a drag preserves selected handles");
}
const centered = await create();
root.firstElementChild.setAttribute("style", "text-align: center");
@@ -186,7 +219,35 @@ const browserCases = async (source: string, resizeSource: string, luteSource: st
const frame = image.parentElement.querySelector<HTMLElement>(".protyle-image-resize");
const move = (x: number, y: number) => require("electron").ipcRenderer.invoke("image-resize-pointer", x, y);
await move(1, 1);
- if (!matchMedia("(pointer: coarse)").matches) {
+ if (matchMedia("(hover: none) and (pointer: coarse)").matches) {
+ const handles = Array.from(frame.querySelectorAll<HTMLElement>(".protyle-block-resize"));
+ const visible = () => handles.map(handle => getComputedStyle(handle).visibility);
+ const hit = (handle: HTMLElement) => {
+ const rect = handle.getBoundingClientRect();
+ return document.elementFromPoint(rect.left + rect.width / 2, rect.top + rect.height / 2);
+ };
+ check.deepEqual(visible(), ["hidden", "hidden", "hidden"], "touch images initially hide all handles");
+ handles.forEach(handle => check.notEqual(hit(handle), handle, "hidden handles do not intercept touches"));
+ const rect = image.getBoundingClientRect();
+ await move(rect.left + rect.width / 2, rect.top + rect.height / 2);
+ check.deepEqual(visible(), ["hidden", "hidden", "hidden"], "touch hover does not reveal unselected handles");
+ tap(image);
+ check.deepEqual(visible(), ["visible", "visible", "visible"], "tapping an image reveals its handles");
+ handles.forEach(handle => check.equal(hit(handle), handle, "selected handles accept touches"));
+ root.insertAdjacentHTML("beforeend", lute.Md2BlockDOM("![another](assets/sample.png)"));
+ const another = root.lastElementChild.querySelector<HTMLImageElement>("img");
+ another.src = url;
+ await another.decode();
+ await settle();
+ tap(another);
+ check.deepEqual(visible(), ["hidden", "hidden", "hidden"], "selecting another image hides the previous handles");
+ const anotherHandle = another.parentElement.querySelector<HTMLElement>(".protyle-block-resize");
+ check.equal(getComputedStyle(anotherHandle).visibility, "visible");
+ tap(root);
+ check.equal(getComputedStyle(anotherHandle).visibility, "hidden", "tapping elsewhere clears selection");
+ root.lastElementChild.remove();
+ tap(image);
+ } else {
const opacity = () => Array.from(frame.querySelectorAll(".protyle-block-resize")).map(handle => getComputedStyle(handle).opacity);
check.deepEqual(opacity(), ["0", "0", "0"]);
const rect = image.getBoundingClientRect();
@@ -236,7 +297,7 @@ const browserCases = async (source: string, resizeSource: string, luteSource: st
return "Image resize cases passed";
};
-test("image handles initialize on insertion and retain source, aspect ratio and replay compatibility", {
+test("image handles retain selection, touch visibility, source, aspect ratio and replay compatibility", {
skip: process.platform === "linux" && !process.env.DISPLAY && !process.env.WAYLAND_DISPLAY,
timeout: 60000,
}, async () => {
@@ -244,14 +305,39 @@ test("image handles initialize on insertion and retain source, aspect ratio and
{compilerOptions: {target: ScriptTarget.ES2021}}).outputText;
const source = createSourceFile("index.ts", readFileSync("src/protyle/wysiwyg/index.ts", "utf8"), ScriptTarget.ES2021, true);
let resize = "";
+ let clearSelection = "";
+ let selectImage = "";
const visit = (node: import("typescript").Node) => {
if (isIfStatement(node) && node.expression.getText(source) === '!protyle.disabled && target.classList.contains("protyle-action__drag")') {
resize = node.getText(source);
}
+ if (isIfStatement(node) && node.expression.getText(source) === "!isToggleBlockDrag" &&
+ node.getText(source).includes('hideElements(["select"], protyle)')) {
+ clearSelection = node.getText(source);
+ }
+ if (isIfStatement(node) && node.expression.getText(source) === "!event.shiftKey && !ctrlIsPressed && imgElement") {
+ selectImage = node.getText(source);
+ }
node.forEachChild(visit);
};
visit(source);
assert.ok(resize);
+ assert.ok(clearSelection);
+ assert.ok(selectImage);
+ const selectionSource = transpileModule(`
+ function clear(target, root) {
+ const protyle = {wysiwyg: {element: root}};
+ const isToggleBlockDrag = false;
+ const avDragFillElement = null;
+ ${clearSelection}
+ }
+ function select(event) {
+ const imgElement = event.target.closest(".img");
+ const ctrlIsPressed = false;
+ const hasNextSibling = () => null;
+ ${selectImage}
+ }
+ `, {compilerOptions: {target: ScriptTarget.ES2021}}).outputText + "\nreturn {clear, select};";
const resizeSource = transpileModule(`function resize() { ${resize} }`, {compilerOptions: {target: ScriptTarget.ES2021}})
.outputText + "\nreturn resize.call(this);";
const css = compileString('@use "protyle/protyle"; @use "component/typography"; @use "business/resize";',
@@ -260,9 +346,9 @@ test("image handles initialize on insertion and retain source, aspect ratio and
{loadPaths: ["src/assets/scss"], logger: {warn() {}, debug() {}}}).css;
const bridgeSources = ["src/util/touchDragBridge.ts", "src/util/touchDragBridgeCore.ts"].map(file =>
transpileModule(readFileSync(file, "utf8"), {compilerOptions: {module: ModuleKind.CommonJS, target: ScriptTarget.ES2021}}).outputText);
- const makeCode = (styles: string) => "const __name = value => value; (" + browserCases.toString() + ")(" +
+ const makeCode = (styles: string, touchMode: boolean) => "const __name = value => value; (" + browserCases.toString() + ")(" +
[transpile("src/protyle/render/imageResize.ts"), resizeSource,
- readFileSync("stage/protyle/js/lute/lute.min.js", "utf8"), styles, ...bridgeSources]
+ readFileSync("stage/protyle/js/lute/lute.min.js", "utf8"), styles, ...bridgeSources, selectionSource, touchMode]
.map(value => JSON.stringify(value)).join(",") + ")";
const temporary = mkdtempSync(path.join(tmpdir(), "siyuan-image-resize-test-"));
const script = path.join(temporary, "run.cjs");
@@ -280,11 +366,11 @@ app.whenReady().then(async () => {
});
try {
await win.loadURL("data:text/html,<html><body></body></html>");
- console.log(await win.webContents.executeJavaScript(${JSON.stringify(makeCode(css))}));
+ console.log(await win.webContents.executeJavaScript(${JSON.stringify(makeCode(css, false))}));
await win.webContents.debugger.sendCommand("Emulation.setTouchEmulationEnabled", {enabled: true});
win.setSize(390, 700);
await win.loadURL("data:text/html,<html><body></body></html>");
- console.log(await win.webContents.executeJavaScript(${JSON.stringify(makeCode(css + mobileCSS))}));
+ console.log(await win.webContents.executeJavaScript(${JSON.stringify(makeCode(css + mobileCSS, true))}));
app.exit(0);
} catch (error) { console.error(error); app.exit(1); }
});`, "utf8");
diff --git a/app/src/protyle/wysiwyg/index.ts b/app/src/protyle/wysiwyg/index.ts
index c20d03036e..6ad62c036f 100644
--- a/app/src/protyle/wysiwyg/index.ts
+++ b/app/src/protyle/wysiwyg/index.ts
@@ -1461,7 +1461,7 @@ export class WYSIWYG {
if (hasClosestByAttribute(target, "data-type", "av-gallery-more")) {
clearSelect(["img", "row", "cell"], protyle.wysiwyg.element);
} else if (!hasClosestByClassName(target, "av__firstcol") && !avDragFillElement) {
- clearSelect(["img", "av"], protyle.wysiwyg.element);
+ clearSelect(target.closest(".protyle-image-resize") ? ["av"] : ["img", "av"], protyle.wysiwyg.element);
}
}