Registering events sooner
This commit is contained in:
71
src/main.ts
71
src/main.ts
@@ -64,45 +64,44 @@ export default class OmnisearchPlugin extends Plugin {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
app.workspace.onLayoutReady(async () => {
|
// Listeners to keep the search index up-to-date
|
||||||
// Listeners to keep the search index up-to-date
|
this.registerEvent(
|
||||||
this.registerEvent(
|
this.app.vault.on('create', async file => {
|
||||||
this.app.vault.on('create', async file => {
|
if (isFileIndexable(file.path)) {
|
||||||
if (isFileIndexable(file.path)) {
|
await cacheManager.addToLiveCache(file.path)
|
||||||
await cacheManager.addToLiveCache(file.path)
|
searchEngine.addFromPaths([file.path])
|
||||||
searchEngine.addFromPaths([file.path])
|
}
|
||||||
}
|
})
|
||||||
})
|
)
|
||||||
)
|
this.registerEvent(
|
||||||
this.registerEvent(
|
this.app.vault.on('delete', file => {
|
||||||
this.app.vault.on('delete', file => {
|
cacheManager.removeFromLiveCache(file.path)
|
||||||
cacheManager.removeFromLiveCache(file.path)
|
searchEngine.removeFromPaths([file.path])
|
||||||
searchEngine.removeFromPaths([file.path])
|
})
|
||||||
})
|
)
|
||||||
)
|
this.registerEvent(
|
||||||
this.registerEvent(
|
this.app.vault.on('modify', async file => {
|
||||||
this.app.vault.on('modify', async file => {
|
if (isFileIndexable(file.path)) {
|
||||||
if (isFileIndexable(file.path)) {
|
await cacheManager.addToLiveCache(file.path)
|
||||||
await cacheManager.addToLiveCache(file.path)
|
NotesIndex.markNoteForReindex(file)
|
||||||
NotesIndex.markNoteForReindex(file)
|
}
|
||||||
}
|
})
|
||||||
})
|
)
|
||||||
)
|
this.registerEvent(
|
||||||
this.registerEvent(
|
this.app.vault.on('rename', async (file, oldPath) => {
|
||||||
this.app.vault.on('rename', async (file, oldPath) => {
|
if (isFileIndexable(file.path)) {
|
||||||
if (isFileIndexable(file.path)) {
|
cacheManager.removeFromLiveCache(oldPath)
|
||||||
cacheManager.removeFromLiveCache(oldPath)
|
cacheManager.addToLiveCache(file.path)
|
||||||
cacheManager.addToLiveCache(file.path)
|
searchEngine.removeFromPaths([oldPath])
|
||||||
searchEngine.removeFromPaths([oldPath])
|
await searchEngine.addFromPaths([file.path])
|
||||||
await searchEngine.addFromPaths([file.path])
|
}
|
||||||
}
|
})
|
||||||
})
|
)
|
||||||
)
|
|
||||||
|
|
||||||
|
app.workspace.onLayoutReady(async () => {
|
||||||
|
this.executeFirstLaunchTasks()
|
||||||
await this.populateIndex()
|
await this.populateIndex()
|
||||||
})
|
})
|
||||||
|
|
||||||
this.executeFirstLaunchTasks()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
executeFirstLaunchTasks(): void {
|
executeFirstLaunchTasks(): void {
|
||||||
|
|||||||
Reference in New Issue
Block a user