Skip to content

Commit a3984dd

Browse files
author
王一帆
committed
v1.7.4
1 parent e7c6c7a commit a3984dd

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "obsidian-file-cooker",
33
"name": "File Cooker",
4-
"version": "1.7.3",
4+
"version": "1.7.4",
55
"minAppVersion": "0.12.0",
66
"description": "Deal multi notes from Search results、current file、Dataview query string...",
77
"author": "iuian",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "obsidian-file-cooker",
3-
"version": "1.7.0",
3+
"version": "1.7.4",
44
"description": "Deal batch notes from Search results、current file、Dataview query string...",
55
"main": "main.js",
66
"scripts": {

src/modal/add-to-canvas-confirm-modal.ts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { App, ItemView, Modal, Notice, requireApiVersion, Setting, TAbstractFile, TFile } from 'obsidian';
22

3+
const width = 400;
4+
const height = 400;
5+
const between = 40;
6+
37
/**
48
*  弹窗确认要添加到Canvas的文件
59
*/
@@ -29,13 +33,18 @@ export class AddToCanvasConfirmModal extends Modal {
2933
.setCta()
3034
.onClick(async () => {
3135
this.close();
32-
let targetFile = this.app.vault.getAbstractFileByPath(this.targetFilePath);
33-
if (targetFile == null) {
34-
console.log("can not find " + this.targetFilePath)
35-
targetFile = await this.app.vault.create(this.targetFilePath, "");
36+
let activeFile = this.app.workspace.getActiveFile();
37+
38+
// 如果当前活动文档与目标文档不同,则尝试打开目标文档
39+
if (activeFile == null || this.targetFilePath != activeFile.path) {
40+
let targetFile = this.app.vault.getAbstractFileByPath(this.targetFilePath);
41+
if (targetFile == null) {
42+
console.log("can not find " + this.targetFilePath)
43+
targetFile = await this.app.vault.create(this.targetFilePath, "");
44+
}
45+
// 如果打开的不是目标文件,则尝试在新窗口打开;如果没有打开任何文件,则在当前窗口打开
46+
await this.app.workspace.getLeaf(activeFile != null).openFile(targetFile as TFile);
3647
}
37-
console.log(targetFile);
38-
await this.app.workspace.getLeaf(true).openFile(targetFile as TFile);
3948

4049
// Conditions to check
4150
const canvasView = app.workspace.getActiveViewOfType(ItemView);
@@ -48,21 +57,21 @@ export class AddToCanvasConfirmModal extends Modal {
4857
let file = this.resultArr[key] as TFile;
4958
let tempChildNode;
5059
if (!requireApiVersion("1.1.10")) {
51-
tempChildNode = canvas.createFileNode(file, "", { x: 20 + (220 * idx), y: 20, height: 200, width: 200 }, true);
60+
tempChildNode = canvas.createFileNode(file, "", { x: between + ((width + between) * idx), y: between, height: height, width: width }, true);
5261
} else {
5362
tempChildNode = canvas.createFileNode({
5463
file: file,
5564
pos: {
56-
x: 20 + (220 * idx),
57-
y: 20,
58-
width: 200,
59-
height: 200
65+
x: between + ((width + between) * idx),
66+
y: between,
67+
width: width,
68+
height: height
6069
},
6170
size: {
62-
x: 20,
63-
y: 20,
64-
width: 200,
65-
height: 200
71+
x: between,
72+
y: between,
73+
width: width,
74+
height: height
6675
},
6776
save: true,
6877
focus: false,

0 commit comments

Comments
 (0)