Skip to content

Commit dd9d588

Browse files
committed
fix: process base files with command
1 parent 69e7247 commit dd9d588

3 files changed

Lines changed: 33 additions & 10 deletions

File tree

src/commands/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ const processNow: GetCommandFn = (plugin) => ({
2020
if (file) {
2121
void plugin?.processMarkdownView(file);
2222
}
23-
const leaf = plugin?.app.workspace.getLeaf(false);
24-
if (leaf?.view && leaf.view instanceof RuleEngineBasesView) {
25-
plugin?.debug(`leaf is RuleEngineBasesView, processing results`);
26-
(leaf.view as RuleEngineBasesView).processView(true);
23+
24+
if (plugin?.activeBasesView) {
25+
plugin?.debug(`activeBasesView, processing results...`, plugin.activeBasesView);
26+
plugin?.activeBasesView?.processView(true);
2727
} else {
28-
plugin?.debug(`leaf is not RuleEngineBasesView, not processing results`, leaf?.view);
28+
plugin?.debug(`no activeBasesView, not processing results`);
2929
};
3030

3131
return true;

src/main.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export default class ObsidianRuleEnginePlugin extends Plugin {
7272
};
7373

7474
public isBasesViewRegistered: boolean = false;
75+
public activeBasesView: RuleEngineBasesView | undefined = undefined;
7576

7677
async onload() {
7778
await this.loadSettings();

src/ruleEngineBasesView.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,19 @@ export class RuleEngineBasesView extends BasesView implements HoverParent {
4040
return (hash >>> 0).toString(16);
4141
}
4242

43+
onload(): void {
44+
this.plugin.activeBasesView = this;
45+
}
46+
onunload(): void {
47+
this.plugin.activeBasesView = undefined;
48+
}
49+
4350
public processView(ignoreDataHash = false): void {
51+
this.plugin?.debug(`processView`, { ignoreDataHash });
52+
//account for base views changing quickly
53+
if (!this.plugin.activeBasesView) {
54+
this.plugin.activeBasesView = this;
55+
}
4456
this.containerEl.empty();
4557

4658
// --- 1. Container Baseline Style ---
@@ -57,6 +69,7 @@ export class RuleEngineBasesView extends BasesView implements HoverParent {
5769

5870
const layoutMode = this.config.get('layout') ?? 'table';
5971
const order = this.config.getOrder();
72+
this.plugin.debug(`applying layout`, layoutMode);
6073

6174
if (layoutMode === 'table') {
6275
const table = this.containerEl.createEl('table');
@@ -95,13 +108,21 @@ export class RuleEngineBasesView extends BasesView implements HoverParent {
95108
}
96109
}
97110

98-
const canProcessCommands = Boolean(this.config.get('enableCommands') && (ignoreDataHash ? true : this.plugin.settings.processBaseResultsAutomatically));
111+
const viewEnabledCommands = Boolean(this.config.get('enableCommands'));
112+
const autoProcess = this.plugin.settings.processBaseResultsAutomatically;
113+
const canProcessCommands = viewEnabledCommands && (ignoreDataHash || autoProcess);
114+
this.plugin.debug(`canProcessCommands`, {
115+
canProcessCommands,
116+
viewEnabledCommands,
117+
ignoreDataHash,
118+
autoProcess
119+
});
99120
if (canProcessCommands) {
100121
const thisHash = this.currentDataHash;
101-
const dataChanged = this.lastDataHash !== thisHash;
102-
// Command execution only takes place if the data has changed, not the order or grouping
103-
if (dataChanged || ignoreDataHash) {
104-
this.plugin.debug(`${dataChanged ? 'data changed' : ignoreDataHash ? 'ignoring data hash' : ''}- processing commands...`)
122+
// Command execution only takes place automatically if the data has changed, not the order or grouping
123+
const willRunCommands = ignoreDataHash || this.lastDataHash !== thisHash;
124+
if (willRunCommands) {
125+
this.plugin.debug(`${willRunCommands ? 'data changed' : ignoreDataHash ? 'ignoring data hash' : ''}- processing commands...`)
105126
const groupLeaf = this.app.workspace.getLeaf("split", "vertical");
106127
groupLeaf.setGroup("ore-leaf-group");
107128
for (const group of this.data.groupedData) {
@@ -112,6 +133,7 @@ export class RuleEngineBasesView extends BasesView implements HoverParent {
112133
}
113134
this.lastDataHash = thisHash;
114135
}
136+
groupLeaf.detach();
115137
}
116138
}
117139
}

0 commit comments

Comments
 (0)