From e622f8d2b8ffc0348a7d5cb788acb906d1dcf435 Mon Sep 17 00:00:00 2001 From: yann300 Date: Tue, 5 Dec 2023 10:10:40 +0100 Subject: [PATCH] load md tab --- apps/doc-viewer/src/app/docviewer.ts | 13 +++++++++++-- apps/remix-ide/src/app/files/fileManager.ts | 1 + 2 files changed, 12 insertions(+), 2 deletions(-) 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 } }