diff --git a/apps/doc-viewer/src/app/docviewer.ts b/apps/doc-viewer/src/app/docviewer.ts index d6fed6e490..30776489b0 100644 --- a/apps/doc-viewer/src/app/docviewer.ts +++ b/apps/doc-viewer/src/app/docviewer.ts @@ -5,6 +5,7 @@ import EventEmitter from 'events' export class DocViewer extends PluginClient { mdFile: string eventEmitter: EventEmitter + refreshId: any constructor() { super() this.eventEmitter = new EventEmitter() @@ -14,9 +15,17 @@ export class DocViewer extends PluginClient { this.onload() } - async viewDocs(docs: string[]) { - this.mdFile = docs[0] + private async refresh() { + if (!this.mdFile) return clearInterval(this.refreshId) const contents = await this.call('fileManager', 'readFile', this.mdFile) this.eventEmitter.emit('contentsReady', contents) } + + async viewDocs(docs: string[]) { + this.mdFile = docs[0] + this.refresh() + this.refreshId = setInterval(async () => { + this.refresh() + }, 500) + } } \ No newline at end of file diff --git a/apps/remix-ide/src/app/files/fileManager.ts b/apps/remix-ide/src/app/files/fileManager.ts index 9b80a5fcf7..cd19ade6ed 100644 --- a/apps/remix-ide/src/app/files/fileManager.ts +++ b/apps/remix-ide/src/app/files/fileManager.ts @@ -741,6 +741,7 @@ class FileManager extends Plugin { // TODO: Only keep `this.emit` (issue#2210) this.emit('currentFileChanged', file) this.events.emit('currentFileChanged', file) + if (file.endsWith('.md')) await this.call('doc-viewer' as any, 'viewDocs', [file]) return true } }