From 7cdc42e1909dd52b0ffdb7b660452797fca05968 Mon Sep 17 00:00:00 2001 From: Vanessa Date: Thu, 12 Dec 2024 10:33:45 +0800 Subject: [PATCH] :art: https://github.com/siyuan-note/siyuan/issues/13336 --- app/src/protyle/upload/index.ts | 19 +++++++++++++------ app/src/protyle/util/paste.ts | 1 + 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/src/protyle/upload/index.ts b/app/src/protyle/upload/index.ts index dbe71bd46..eef0ad793 100644 --- a/app/src/protyle/upload/index.ts +++ b/app/src/protyle/upload/index.ts @@ -9,6 +9,7 @@ import {genAssetHTML} from "../../asset/renderAssets"; import {hasClosestBlock} from "../util/hasClosest"; import {getContenteditableElement} from "../wysiwyg/getBlock"; import {getTypeByCellElement, updateCellsValue} from "../render/av/cell"; +import {scrollCenter} from "../../util/highlightById"; export class Upload { public element: HTMLElement; @@ -118,28 +119,30 @@ const genUploadedLabel = (responseText: string, protyle: IProtyle) => { } } } - let succFileText = ""; + let successFileText = ""; const keys = Object.keys(response.data.succMap); const avAssets: IAVCellAssetValue[] = []; + let hasImage = false; keys.forEach((key, index) => { const path = response.data.succMap[key]; const type = pathPosix().extname(key).toLowerCase(); const filename = protyle.options.upload.filename(key); const name = filename.substring(0, filename.length - type.length); + hasImage = Constants.SIYUAN_ASSETS_IMAGE.includes(type) avAssets.push({ type: Constants.SIYUAN_ASSETS_IMAGE.includes(type) ? "image" : "file", content: path, name: name }); - succFileText += genAssetHTML(type, path, name, filename); + successFileText += genAssetHTML(type, path, name, filename); if (!Constants.SIYUAN_ASSETS_AUDIO.includes(type) && !Constants.SIYUAN_ASSETS_VIDEO.includes(type) && keys.length - 1 !== index) { if (nodeElement && nodeElement.classList.contains("table")) { - succFileText += "
"; + successFileText += "
"; } else if (insertBlock) { - succFileText += "\n\n"; + successFileText += "\n\n"; } else { - succFileText += "\n"; + successFileText += "\n"; } } }); @@ -191,7 +194,11 @@ const genUploadedLabel = (responseText: string, protyle: IProtyle) => { } } // 避免插入代码块中,其次因为都要独立成块 https://github.com/siyuan-note/siyuan/issues/7607 - insertHTML(succFileText, protyle, insertBlock); + insertHTML(successFileText, protyle, insertBlock); + // 粘贴图片后定位不准确 https://github.com/siyuan-note/siyuan/issues/13336 + setTimeout(() => { + scrollCenter(protyle, undefined, false, "smooth"); + }, hasImage ? 0 : Constants.TIMEOUT_LOAD); }; export const uploadLocalFiles = (files: string[], protyle: IProtyle, isUpload: boolean) => { diff --git a/app/src/protyle/util/paste.ts b/app/src/protyle/util/paste.ts index c79045ca6..f87de1273 100644 --- a/app/src/protyle/util/paste.ts +++ b/app/src/protyle/util/paste.ts @@ -502,6 +502,7 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven return; } else if (files && files.length > 0) { uploadFiles(protyle, files); + return; } else if (textPlain.trim() !== "" && files && files.length === 0) { if (range.toString() !== "") { const firstLine = textPlain.split("\n")[0];