Skip to content

Commit 71cd6e4

Browse files
committed
fixed a bug
1 parent f7d3bb0 commit 71cd6e4

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

main.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,23 @@ export default class AnotherNamePlugin extends Plugin {
2727
inlineTitle = mdView?.inlineTitleEl;
2828

2929
// remove old element if exists
30-
console.log("viewContentEl", viewContentEl);
30+
// console.log("viewContentEl", viewContentEl);
3131

32-
// wait for the element to be rendered. At least it works!
32+
// wait a while for the element to be rendered. At least it works!
3333
let time = 0;
3434
while (time < 100) {
35+
const startTime = Date.now();
3536
await sleep(10);
36-
time += 10;
3737
if (viewContentEl.querySelector(".another-name")) {
3838
break;
3939
}
40+
const endTime = Date.now();
41+
time += endTime - startTime;
42+
// console.log(time);
4043
}
4144

4245
const anotherNameElOld = viewContentEl.querySelector(".another-name");
43-
console.log("anotherNameElOld", anotherNameElOld);
46+
// console.log("anotherNameElOld", anotherNameElOld);
4447
if (anotherNameElOld) {
4548
anotherNameElOld.remove();
4649
// anotherNameElOld.forEach((el: HTMLElement) => {
@@ -83,8 +86,8 @@ export default class AnotherNamePlugin extends Plugin {
8386
if (!file) return;
8487
const cache = this.app.metadataCache.getFileCache(file);
8588
if (cache) {
86-
console.log("reloadAllVisible");
87-
console.log(file, cache, leaf);
89+
// console.log("reloadAllVisible");
90+
// console.log(file, cache, leaf);
8891
this.reloadForFile(file, cache, leaf);
8992
}
9093
});
@@ -115,25 +118,25 @@ export default class AnotherNamePlugin extends Plugin {
115118

116119
this.registerEvent(this.app.metadataCache.on('changed', (file: TFile, data: string, cache: CachedMetadata) => {
117120
if (file) {
118-
console.log("changed")
121+
// console.log("changed")
119122
this.reloadForFile(file, cache);
120123
}
121124
}));
122125

123126
this.registerEvent(this.app.workspace.on('layout-change', () => {
124127
// NOTE: I don't know how to make it better. At least it works!
125-
console.log("layout-change");
128+
// console.log("layout-change");
126129
this.reloadAllVisible();
127130
}));
128131

129132
// If the plugin hooks up any global DOM events (on parts of the app that doesn't belong to this plugin)
130133
// Using this function will automatically remove the event listener when this plugin is disabled.
131-
this.registerDomEvent(document, 'click', (evt: MouseEvent) => {
132-
// console.log('click', evt);
133-
});
134+
// this.registerDomEvent(document, 'click', (evt: MouseEvent) => {
135+
// // console.log('click', evt);
136+
// });
134137

135138
// When registering intervals, this function will automatically clear the interval when the plugin is disabled.
136-
this.registerInterval(window.setInterval(() => console.log('setInterval'), 5 * 60 * 1000));
139+
// this.registerInterval(window.setInterval(() => console.log('setInterval'), 5 * 60 * 1000));
137140

138141
}
139142

0 commit comments

Comments
 (0)