Registering events sooner

This commit is contained in:
Simon Cambier
2023-01-19 08:37:43 +01:00
parent 8942e662d6
commit ebee93a2aa

View File

@@ -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 {