From 4cf5e9da4a5c85546671fd1743226b8278a02759 Mon Sep 17 00:00:00 2001 From: oqyude Date: Sat, 11 Jul 2026 03:43:26 +0300 Subject: [PATCH] fix with paragraphs --- manifest.json | 2 +- package.json | 2 +- src/modules/attachment-clean-paste/index.ts | 45 ++++++++++++--------- 3 files changed, 27 insertions(+), 22 deletions(-) diff --git a/manifest.json b/manifest.json index 9e79ba2..7b15900 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "zeroq-qol-modules", "name": "ZeroQ QoL Modules", - "version": "1.1.0", + "version": "1.1.1", "minAppVersion": "0.15.0", "description": "QoL Modules", "author": "oqyude", diff --git a/package.json b/package.json index 0b326b3..e5e5512 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zeroq-qol-modules", - "version": "1.1.0", + "version": "1.1.1", "description": "Modular Obsidian plugin with toggleable QoL modules", "main": "main.js", "scripts": { diff --git a/src/modules/attachment-clean-paste/index.ts b/src/modules/attachment-clean-paste/index.ts index 7cd7d28..a21442e 100644 --- a/src/modules/attachment-clean-paste/index.ts +++ b/src/modules/attachment-clean-paste/index.ts @@ -71,6 +71,26 @@ export class AttachmentCleanPasteModule extends BaseModule { }); } + private async processAll( + files: FileList, + editor: Editor, + settings: AttachmentCleanPasteSettings, + ): Promise { + const matchingFiles = Array.from(files).filter((f) => + this.shouldProcess(f.name, settings), + ); + if (matchingFiles.length === 0) return; + + const links: string[] = []; + for (const file of matchingFiles) { + const link = await this.processFile(file, settings); + if (link) links.push(link); + } + if (links.length === 0) return; + + editor.replaceSelection(links.join('\n\n')); + } + private createPasteHandler(settings: AttachmentCleanPasteSettings) { return async ( evt: ClipboardEvent, @@ -80,17 +100,10 @@ export class AttachmentCleanPasteModule extends BaseModule { const files = evt.clipboardData?.files; if (!files || files.length === 0) return; - const matchingFiles = Array.from(files).filter((f) => - this.shouldProcess(f.name, settings), - ); - if (matchingFiles.length === 0) return; - evt.preventDefault(); evt.stopPropagation(); - for (const file of matchingFiles) { - await this.processFile(file, editor, settings); - } + await this.processAll(files, editor, settings); }; } @@ -103,17 +116,10 @@ export class AttachmentCleanPasteModule extends BaseModule { const files = evt.dataTransfer?.files; if (!files || files.length === 0) return; - const matchingFiles = Array.from(files).filter((f) => - this.shouldProcess(f.name, settings), - ); - if (matchingFiles.length === 0) return; - evt.preventDefault(); evt.stopPropagation(); - for (const file of matchingFiles) { - await this.processFile(file, editor, settings); - } + await this.processAll(files, editor, settings); }; } @@ -138,9 +144,8 @@ export class AttachmentCleanPasteModule extends BaseModule { private async processFile( file: File, - editor: Editor, _settings: AttachmentCleanPasteSettings, - ): Promise { + ): Promise { try { const arrayBuffer = await file.arrayBuffer(); const filename = file.name; @@ -166,11 +171,11 @@ export class AttachmentCleanPasteModule extends BaseModule { await this.app.vault.createBinary(availablePath, arrayBuffer); - const link = `[[${availablePath}|${nameWithoutExt}]]`; - editor.replaceSelection(link); + return `[[${availablePath}|${nameWithoutExt}]]`; } catch (e) { new Notice(`Clean Paste error: ${e.message}`); console.error('Attachment Clean Paste:', e); } + return null; } }