Skip to content

Commit

Permalink
feat: Section rollers generated inside a tag roller are now contextua…
Browse files Browse the repository at this point in the history
…lized properly
  • Loading branch information
valentine195 committed Sep 25, 2024
1 parent 08a1c08 commit f3d7ef2
Showing 1 changed file with 12 additions and 28 deletions.
40 changes: 12 additions & 28 deletions src/roller/tag.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { App, Component, MarkdownRenderer, Notice } from "obsidian";
import type { LexicalToken } from "src/lexer/lexer";
import { TAG_REGEX, DATAVIEW_REGEX } from "src/utils/constants";
import { BasicRoller } from "./roller";
import { BasicRoller, type ComponentLike } from "./roller";
import { SectionRoller } from "./section";
import type { DiceRollerSettings } from "src/settings/settings.types";
import { DataviewManager } from "src/api/api.dataview";
Expand All @@ -15,6 +15,15 @@ abstract class DataViewEnabledRoller extends BasicRoller<SectionRoller> {
types: string;
results: SectionRoller[];

#components: ComponentLike[] = [];
override addContexts(...components: ComponentLike[]): void {
this.#components = components;
super.addContexts(...components);
}
onunload(): void {
this.#components = [];
}

async getReplacer() {
if (this.isLink) {
return `[[${this.result.file.basename}]]`;
Expand Down Expand Up @@ -129,6 +138,7 @@ abstract class DataViewEnabledRoller extends BasicRoller<SectionRoller> {
);
/* await roller.roll(); */
this.results.push(roller);
roller.addContexts(...this.#components);
resolve();
})
);
Expand All @@ -149,7 +159,7 @@ abstract class DataViewEnabledRoller extends BasicRoller<SectionRoller> {
const clone = new Map(this.results.map((r, i) => [i, r]));
for (let i = 0; i < this.rolls; i++) {
if (!clone.size) continue;
const result = this.getRandomBetween(0, clone.size);
const result = this.getRandomBetween(0, clone.size - 1);
const cloned = clone.get(result);
await cloned.roll();
results.push(cloned);
Expand All @@ -172,32 +182,6 @@ abstract class DataViewEnabledRoller extends BasicRoller<SectionRoller> {
);
} else {
for (const result of results) {
/* const link = this.resultEl.createEl("a", {
cls: "internal-link",
text: result.file.basename
});
link.onclick = async (evt) => {
evt.stopPropagation();
this.app.workspace.openLinkText(
result.path,
this.app.workspace.getActiveFile()?.path,
evt.getModifierState("Control")
);
};
link.onmouseenter = async (evt) => {
this.app.workspace.trigger(
"link-hover",
this, //not sure
link, //targetEl
result.path, //linkText
this.app.workspace.getActiveFile()?.path //source
);
};
if (results.length > 1 && r != results.length - 1) {
this.resultEl.createSpan({ text: ", " });
} */

const container = this.resultEl.createDiv();
container.createEl("h5", {
cls: "dice-file-name",
Expand Down

0 comments on commit f3d7ef2

Please sign in to comment.