load md tab

pull/4301/head
yann300 12 months ago
parent 9eaaa5170f
commit e622f8d2b8
  1. 13
      apps/doc-viewer/src/app/docviewer.ts
  2. 1
      apps/remix-ide/src/app/files/fileManager.ts

@ -5,6 +5,7 @@ import EventEmitter from 'events'
export class DocViewer extends PluginClient { export class DocViewer extends PluginClient {
mdFile: string mdFile: string
eventEmitter: EventEmitter eventEmitter: EventEmitter
refreshId: any
constructor() { constructor() {
super() super()
this.eventEmitter = new EventEmitter() this.eventEmitter = new EventEmitter()
@ -14,9 +15,17 @@ export class DocViewer extends PluginClient {
this.onload() this.onload()
} }
async viewDocs(docs: string[]) { private async refresh() {
this.mdFile = docs[0] if (!this.mdFile) return clearInterval(this.refreshId)
const contents = await this.call('fileManager', 'readFile', this.mdFile) const contents = await this.call('fileManager', 'readFile', this.mdFile)
this.eventEmitter.emit('contentsReady', contents) this.eventEmitter.emit('contentsReady', contents)
} }
async viewDocs(docs: string[]) {
this.mdFile = docs[0]
this.refresh()
this.refreshId = setInterval(async () => {
this.refresh()
}, 500)
}
} }

@ -741,6 +741,7 @@ class FileManager extends Plugin {
// TODO: Only keep `this.emit` (issue#2210) // TODO: Only keep `this.emit` (issue#2210)
this.emit('currentFileChanged', file) this.emit('currentFileChanged', file)
this.events.emit('currentFileChanged', file) this.events.emit('currentFileChanged', file)
if (file.endsWith('.md')) await this.call('doc-viewer' as any, 'viewDocs', [file])
return true return true
} }
} }

Loading…
Cancel
Save