Skip to content

Commit db3f55e

Browse files
committed
fix: fixed checkbox behavior in admonitions (close #135)
1 parent 169f0e3 commit db3f55e

File tree

1 file changed

+12
-23
lines changed

1 file changed

+12
-23
lines changed

src/main.ts

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -781,29 +781,18 @@ ${editor.getDoc().getSelection()}\n--- admonition\n`
781781
admonitionContent.querySelectorAll<HTMLInputElement>(
782782
".task-list-item-checkbox"
783783
);
784-
if (taskLists.length) {
785-
const file = this.app.vault.getAbstractFileByPath(
786-
ctx.sourcePath
787-
);
788-
const section = ctx.getSectionInfo(el);
789-
if (file && section) {
790-
const split = src.split("\n");
791-
let slicer = 0;
792-
taskLists.forEach((task) => {
793-
const line =
794-
src.slice(slicer).search(/^\- \[.\]/m) + slicer;
795-
slicer = src.indexOf("\n", line);
796-
const box = src.slice(line, slicer).search(/\[.\]/);
797-
console.log(
798-
"🚀 ~ file: main.ts ~ line 797 ~ box",
799-
box
800-
);
801-
802-
task.onclick = (e) => {
803-
const { text, lineStart } = section;
804-
};
805-
});
806-
}
784+
if (taskLists?.length) {
785+
const split = src.split("\n");
786+
let slicer = 0;
787+
taskLists.forEach((task) => {
788+
const line = split
789+
.slice(slicer)
790+
.findIndex((l) => /^\- \[.\]/.test(l));
791+
792+
if (line == -1) return;
793+
task.dataset.line = `${line + slicer + 1}`;
794+
slicer = line + slicer + 1;
795+
});
807796
}
808797

809798
const links =

0 commit comments

Comments
 (0)