Skip to content

Commit d9821cb

Browse files
committed
🐛 modal supports notes embedded in canvas
1 parent 1ecfbb3 commit d9821cb

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/taskcollector-Plugin.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
MarkdownPostProcessor,
1010
MarkdownPreviewRenderer,
1111
MarkdownFileInfo,
12+
TFile,
1213
} from "obsidian";
1314
import { Direction, TaskCollector } from "./taskcollector-TaskCollector";
1415
import { TaskCollectorSettingsTab } from "./taskcollector-SettingsTab";
@@ -82,7 +83,15 @@ export class TaskCollectorPlugin extends Plugin {
8283

8384
async editLines(mark: string, lines?: number[]): Promise<void> {
8485
const activeFile = this.app.workspace.getActiveFile();
85-
await this.app.vault.process(activeFile, (source): string => {
86+
await this.editLinesInFile(activeFile, mark, lines);
87+
}
88+
89+
async editLinesInFile(
90+
file: TFile,
91+
mark: string,
92+
lines?: number[],
93+
): Promise<void> {
94+
await this.app.vault.process(file, (source): string => {
8695
return this.tc.markSelectedTask(source, mark, lines);
8796
});
8897
}
@@ -420,10 +429,13 @@ export class TaskCollectorPlugin extends Plugin {
420429
el.querySelectorAll<HTMLInputElement>(
421430
".task-list-item-checkbox",
422431
);
423-
if (!checkboxes.length) return;
432+
if (!checkboxes.length || !ctx.sourcePath) {
433+
return;
434+
}
424435

425436
const isLivePreview =
426437
!!el.closest(".markdown-rendered");
438+
427439
this.tc.logDebug(
428440
"markdown postprocessor",
429441
`use context menu: ${this.tc.cache.useContextMenu};`,
@@ -433,6 +445,10 @@ export class TaskCollectorPlugin extends Plugin {
433445
checkboxes,
434446
);
435447

448+
const targetFile = this.app.vault.getFileByPath(
449+
ctx.sourcePath,
450+
);
451+
436452
for (const checkbox of Array.from(checkboxes)) {
437453
const section = ctx.getSectionInfo(checkbox);
438454
if (!section) continue;
@@ -480,9 +496,11 @@ export class TaskCollectorPlugin extends Plugin {
480496
this.tc,
481497
);
482498
if (mark) {
483-
await this.editLines(mark, [
484-
lineStart + line,
485-
]);
499+
await this.editLinesInFile(
500+
targetFile,
501+
mark,
502+
[lineStart + line],
503+
);
486504
}
487505
},
488506
);

0 commit comments

Comments
 (0)