highlight content

pull/1/head
yann300 7 years ago
parent 351676dcd5
commit 2fc0d245db
  1. 43
      src/app/editor/sourceHighlighter.js
  2. 2
      src/app/panels/righthand-panel.js
  3. 13
      src/app/plugin/pluginAPI.js

@ -4,20 +4,6 @@ var globlalRegistry = require('../../global/registry')
var styleGuide = require('../ui/styles-guide/theme-chooser') var styleGuide = require('../ui/styles-guide/theme-chooser')
var styles = styleGuide.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 { class SourceHighlighter {
constructor (localRegistry) { constructor (localRegistry) {
const self = this const self = this
@ -36,18 +22,45 @@ class SourceHighlighter {
} }
currentSourceLocation (lineColumnPos, location) { 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.statementMarker) this._deps.editor.removeMarker(this.statementMarker, this.source)
if (this.fullLineMarker) this._deps.editor.removeMarker(this.fullLineMarker, this.source) if (this.fullLineMarker) this._deps.editor.removeMarker(this.fullLineMarker, this.source)
this.statementMarker = null this.statementMarker = null
this.fullLineMarker = null this.fullLineMarker = null
this.source = null this.source = null
if (lineColumnPos) { if (lineColumnPos) {
this.source = this._deps.compiler.getSourceName(location.file) this.source = filePath
if (this._deps.config.get('currentFile') !== this.source) { if (this._deps.config.get('currentFile') !== this.source) {
this._deps.fileManager.switchFile(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.statementMarker = this._deps.editor.addMarker(lineColumnPos, this.source, css.highlightcode)
this._deps.editor.scrollToLine(lineColumnPos.start.line, true, true, function () {}) this._deps.editor.scrollToLine(lineColumnPos.start.line, true, true, function () {})
if (lineColumnPos.start.line === lineColumnPos.end.line) { if (lineColumnPos.start.line === lineColumnPos.end.line) {
this.fullLineMarker = this._deps.editor.addMarker({ this.fullLineMarker = this._deps.editor.addMarker({
start: { start: {

@ -36,7 +36,7 @@ module.exports = class RighthandPanel {
self._deps = { self._deps = {
fileProviders: self._components.registry.get('fileproviders').api, 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, compiler: self._components.registry.get('compiler').api,
udapp: self._components.registry.get('udapp').api, udapp: self._components.registry.get('udapp').api,
app: self._components.registry.get('app').api, app: self._components.registry.get('app').api,

@ -1,10 +1,11 @@
'use strict' 'use strict'
var executionContext = require('../../execution-context') var executionContext = require('../../execution-context')
var SourceHighlighter = require('../editor/sourceHighlighter')
/* /*
Defines available API. `key` / `type` Defines available API. `key` / `type`
*/ */
module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) => { module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) => {
var highlighter = new SourceHighlighter()
return { return {
app: { app: {
getExecutionContextProvider: (mod, cb) => { getExecutionContextProvider: (mod, cb) => {
@ -76,22 +77,28 @@ module.exports = (pluginManager, fileProviders, fileManager, compiler, udapp) =>
getFile: (mod, path, cb) => { getFile: (mod, path, cb) => {
var provider = fileManager.fileProviderOf(path) var provider = fileManager.fileProviderOf(path)
if (provider) { if (provider) {
// TODO add approval to user for external plugin to get the content of the given `path`
provider.get(mod + '/' + path, (error, content) => { provider.get(mod + '/' + path, (error, content) => {
cb(error, content) cb(error, content)
}) })
} else { } else {
cb(path + 'not available') cb(path + ' not available')
} }
}, },
setFile: (mod, path, content, cb) => { setFile: (mod, path, content, cb) => {
var provider = fileManager.fileProviderOf(path) var provider = fileManager.fileProviderOf(path)
if (provider) { if (provider) {
// TODO add approval to user for external plugin to set the content of the given `path`
provider.set(mod + '/' + path, content, (error) => { provider.set(mod + '/' + path, content, (error) => {
cb(error) cb(error)
}) })
} else { } else {
cb(path + 'not available') cb(path + ' not available')
} }
},
highlight: (mod, lineColumnPos, filePath, hexColor, cb) => {
highlighter.currentSourceLocation(null)
highlighter.currentSourceLocation(lineColumnPos, filePath, hexColor)
} }
} }
} }

Loading…
Cancel
Save