pull/5370/head
bunsenstraat 3 years ago
parent 1b19874d46
commit ffbe09a017
  1. 56
      apps/remix-ide/src/app/editor/editor.js

@ -4,6 +4,7 @@ import ReactDOM from 'react-dom'
import { EditorUI } from '@remix-ui/editor' // eslint-disable-line import { EditorUI } from '@remix-ui/editor' // eslint-disable-line
import { Plugin } from '@remixproject/engine' import { Plugin } from '@remixproject/engine'
import * as packageJson from '../../../../../package.json' import * as packageJson from '../../../../../package.json'
import { ViewPluginUI } from '../plugins/ViewPluginUI'
const EventManager = require('../../lib/events') const EventManager = require('../../lib/events')
@ -62,15 +63,39 @@ class Editor extends Plugin {
// to be implemented by the react component // to be implemented by the react component
this.api = {} this.api = {}
this.dispatch = null this.dispatch = null
this.ref = null
} }
setDispatch (dispatch) { setDispatch (dispatch) {
this.dispatch = dispatch this.dispatch = dispatch
this.renderComponent()
this.ref.currentContent = () => this.currentContent() // used by e2e test
this.ref.setCurrentContent = (value) => {
if (this.sessions[this.currentFile]) {
this.sessions[this.currentFile].setValue(value)
this._onChange(this.currentFile)
}
}
this.ref.gotoLine = (line, column) => this.gotoLine(line, column || 0)
this.ref.getCursorPosition = () => this.getCursorPosition()
}
updateComponent(state) {
console.log(state)
return <EditorUI
editorAPI={state.api}
themeType={state.currentThemeType}
currentFile={state.currentFile}
sourceAnnotationsPerFile={state.sourceAnnotationsPerFile}
markerPerFile={state.markerPerFile}
events={state.events}
plugin={state.plugin}
/>
} }
render () { render () {
if (this.el) return this.el
/* if (this.el) return this.el
this.el = document.createElement('div') this.el = document.createElement('div')
this.el.setAttribute('id', 'editorView') this.el.setAttribute('id', 'editorView')
@ -82,22 +107,23 @@ class Editor extends Plugin {
} }
} }
this.el.gotoLine = (line, column) => this.gotoLine(line, column || 0) this.el.gotoLine = (line, column) => this.gotoLine(line, column || 0)
this.el.getCursorPosition = () => this.getCursorPosition() this.el.getCursorPosition = () => this.getCursorPosition() */
return this.el
return <div ref={(element)=>{ this.ref = element}} id='editorView'>
<ViewPluginUI plugin={this} />
</div>
} }
renderComponent () { renderComponent () {
ReactDOM.render( this.dispatch({
<EditorUI api: this.api,
editorAPI={this.api} currentThemeType: this.currentThemeType,
themeType={this.currentThemeType} currentFile: this.currentFile,
currentFile={this.currentFile} sourceAnnotationsPerFile: this.sourceAnnotationsPerFile,
sourceAnnotationsPerFile={this.sourceAnnotationsPerFile} markerPerFile: this.markerPerFile,
markerPerFile={this.markerPerFile} events: this.events,
events={this.events} plugin: this
plugin={this} })
/>
, this.el)
} }
triggerEvent (name, params) { triggerEvent (name, params) {

Loading…
Cancel
Save