Compare commits
1
Commits
v1.1.0
...
4cf5e9da4a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4cf5e9da4a |
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"id": "zeroq-qol-modules",
|
"id": "zeroq-qol-modules",
|
||||||
"name": "ZeroQ QoL Modules",
|
"name": "ZeroQ QoL Modules",
|
||||||
"version": "1.1.0",
|
"version": "1.1.1",
|
||||||
"minAppVersion": "0.15.0",
|
"minAppVersion": "0.15.0",
|
||||||
"description": "QoL Modules",
|
"description": "QoL Modules",
|
||||||
"author": "oqyude",
|
"author": "oqyude",
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "zeroq-qol-modules",
|
"name": "zeroq-qol-modules",
|
||||||
"version": "1.1.0",
|
"version": "1.1.1",
|
||||||
"description": "Modular Obsidian plugin with toggleable QoL modules",
|
"description": "Modular Obsidian plugin with toggleable QoL modules",
|
||||||
"main": "main.js",
|
"main": "main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -71,6 +71,26 @@ export class AttachmentCleanPasteModule extends BaseModule {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async processAll(
|
||||||
|
files: FileList,
|
||||||
|
editor: Editor,
|
||||||
|
settings: AttachmentCleanPasteSettings,
|
||||||
|
): Promise<void> {
|
||||||
|
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) {
|
private createPasteHandler(settings: AttachmentCleanPasteSettings) {
|
||||||
return async (
|
return async (
|
||||||
evt: ClipboardEvent,
|
evt: ClipboardEvent,
|
||||||
@@ -80,17 +100,10 @@ export class AttachmentCleanPasteModule extends BaseModule {
|
|||||||
const files = evt.clipboardData?.files;
|
const files = evt.clipboardData?.files;
|
||||||
if (!files || files.length === 0) return;
|
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.preventDefault();
|
||||||
evt.stopPropagation();
|
evt.stopPropagation();
|
||||||
|
|
||||||
for (const file of matchingFiles) {
|
await this.processAll(files, editor, settings);
|
||||||
await this.processFile(file, editor, settings);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,17 +116,10 @@ export class AttachmentCleanPasteModule extends BaseModule {
|
|||||||
const files = evt.dataTransfer?.files;
|
const files = evt.dataTransfer?.files;
|
||||||
if (!files || files.length === 0) return;
|
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.preventDefault();
|
||||||
evt.stopPropagation();
|
evt.stopPropagation();
|
||||||
|
|
||||||
for (const file of matchingFiles) {
|
await this.processAll(files, editor, settings);
|
||||||
await this.processFile(file, editor, settings);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,9 +144,8 @@ export class AttachmentCleanPasteModule extends BaseModule {
|
|||||||
|
|
||||||
private async processFile(
|
private async processFile(
|
||||||
file: File,
|
file: File,
|
||||||
editor: Editor,
|
|
||||||
_settings: AttachmentCleanPasteSettings,
|
_settings: AttachmentCleanPasteSettings,
|
||||||
): Promise<void> {
|
): Promise<string | null> {
|
||||||
try {
|
try {
|
||||||
const arrayBuffer = await file.arrayBuffer();
|
const arrayBuffer = await file.arrayBuffer();
|
||||||
const filename = file.name;
|
const filename = file.name;
|
||||||
@@ -166,11 +171,11 @@ export class AttachmentCleanPasteModule extends BaseModule {
|
|||||||
|
|
||||||
await this.app.vault.createBinary(availablePath, arrayBuffer);
|
await this.app.vault.createBinary(availablePath, arrayBuffer);
|
||||||
|
|
||||||
const link = `[[${availablePath}|${nameWithoutExt}]]`;
|
return `[[${availablePath}|${nameWithoutExt}]]`;
|
||||||
editor.replaceSelection(link);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
new Notice(`Clean Paste error: ${e.message}`);
|
new Notice(`Clean Paste error: ${e.message}`);
|
||||||
console.error('Attachment Clean Paste:', e);
|
console.error('Attachment Clean Paste:', e);
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user