diff --git a/src/app/editor/sourceHighlighter.js b/src/app/editor/sourceHighlighter.js index 13839c6c73..8a64d52580 100644 --- a/src/app/editor/sourceHighlighter.js +++ b/src/app/editor/sourceHighlighter.js @@ -4,20 +4,6 @@ var globlalRegistry = require('../../global/registry') var styleGuide = require('../ui/styles-guide/theme-chooser') var styles = styleGuide.chooser() -var css = csjs` - .highlightcode { - position:absolute; - z-index:20; - background-color: ${styles.editor.backgroundColor_DebuggerMode}; - } - .highlightcode_fullLine { - position:absolute; - z-index:20; - background-color: ${styles.editor.backgroundColor_DebuggerMode}; - opacity: 0.5; - } -` - class SourceHighlighter { constructor (localRegistry) { const self = this @@ -36,18 +22,45 @@ class SourceHighlighter { } currentSourceLocation (lineColumnPos, location) { + if (this.statementMarker) this._deps.editor.removeMarker(this.statementMarker, this.source) + if (this.fullLineMarker) this._deps.editor.removeMarker(this.fullLineMarker, this.source) + if (location && location.file !== undefined) { + var path = this._deps.compiler.getSourceName(location.file) + if (path) { + this.currentSourceLocationFromfileName(lineColumnPos, path) + } + } + } + + currentSourceLocationFromfileName (lineColumnPos, filePath, style) { if (this.statementMarker) this._deps.editor.removeMarker(this.statementMarker, this.source) if (this.fullLineMarker) this._deps.editor.removeMarker(this.fullLineMarker, this.source) this.statementMarker = null this.fullLineMarker = null this.source = null if (lineColumnPos) { - this.source = this._deps.compiler.getSourceName(location.file) + this.source = filePath if (this._deps.config.get('currentFile') !== this.source) { this._deps.fileManager.switchFile(this.source) } + + var css = csjs` + .highlightcode { + position:absolute; + z-index:20; + background-color: ${style || styles.editor.backgroundColor_DebuggerMode}; + } + .highlightcode_fullLine { + position:absolute; + z-index:20; + background-color: ${style || styles.editor.backgroundColor_DebuggerMode}; + opacity: 0.5; + } + ` + this.statementMarker = this._deps.editor.addMarker(lineColumnPos, this.source, css.highlightcode) this._deps.editor.scrollToLine(lineColumnPos.start.line, true, true, function () {}) + if (lineColumnPos.start.line === lineColumnPos.end.line) { this.fullLineMarker = this._deps.editor.addMarker({ start: { diff --git a/src/app/panels/righthand-panel.js b/src/app/panels/righthand-panel.js index c4a9784bf4..969d5f5525 100644 --- a/src/app/panels/righthand-panel.js +++ b/src/app/panels/righthand-panel.js @@ -36,7 +36,7 @@ module.exports = class RighthandPanel { self._deps = { fileProviders: self._components.registry.get('fileproviders').api, - fileManager: self._components.registry.get('fileManager').api, + fileManager: self._components.registry.get('filemanager').api, compiler: self._components.registry.get('compiler').api, udapp: self._components.registry.get('udapp').api, app: self._components.registry.get('app').api, diff --git a/src/app/plugin/pluginAPI.js b/src/app/plugin/pluginAPI.js index 39d28c8184..a1fdae2aae 100644 --- a/src/app/plugin/pluginAPI.js +++ b/src/app/plugin/pluginAPI.js @@ -1,10 +1,11 @@ 'use strict' var executionContext = require('../../execution-context') - +var SourceHighlighter = require('../editor/sourceHighlighter') /* Defines available API. `key` / `type` */ module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) => { + var highlighter = new SourceHighlighter() return { app: { getExecutionContextProvider: (mod, cb) => { @@ -76,22 +77,28 @@ module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) => getFile: (mod, path, cb) => { var provider = fileManager.fileProviderOf(path) if (provider) { + // TODO add approval to user for external plugin to get the content of the given `path` provider.get(mod + '/' + path, (error, content) => { cb(error, content) }) } else { - cb(path + 'not available') + cb(path + ' not available') } }, setFile: (mod, path, content, cb) => { var provider = fileManager.fileProviderOf(path) if (provider) { + // TODO add approval to user for external plugin to set the content of the given `path` provider.set(mod + '/' + path, content, (error) => { cb(error) }) } else { - cb(path + 'not available') + cb(path + ' not available') } + }, + highlight: (mod, lineColumnPos, filePath, hexColor, cb) => { + highlighter.currentSourceLocation(null) + highlighter.currentSourceLocation(lineColumnPos, filePath, hexColor) } } }