allow multiple highlight per plugin

pull/5370/head
yann300 5 years ago
parent 43864f9c4b
commit 9fb6e1f642
  1. 25
      src/app/editor/SourceHighlighters.js
  2. 12
      src/app/editor/editor.js
  3. 3
      src/app/editor/sourceHighlighter.js
  4. 50
      test-browser/tests/editor.test.js

@ -12,16 +12,33 @@ class SourceHighlighters {
highlight (position, filePath, hexColor, from) {
try {
if (!this.highlighters[from]) this.highlighters[from] = new SourceHighlighter()
this.highlighters[from].currentSourceLocation(null)
this.highlighters[from].currentSourceLocationFromfileName(position, filePath, hexColor)
if (!this.highlighters[from]) this.highlighters[from] = []
const sourceHighlight = new SourceHighlighter()
sourceHighlight.currentSourceLocationFromfileName(position, filePath, hexColor)
this.highlighters[from].push(sourceHighlight)
} catch (e) {
throw e
}
}
discardHighlight (from) {
if (this.highlighters[from]) this.highlighters[from].currentSourceLocation(null)
if (this.highlighters[from]) {
for (const index in this.highlighters[from]) this.highlighters[from][index].currentSourceLocation(null)
}
this.highlighters[from] = []
}
discardHighlightAt (line, filePath, from) {
if (this.highlighters[from]) {
for (const index in this.highlighters[from]) {
const highlight = this.highlighters[from][index]
if (highlight.source === filePath &&
(highlight.position.start.line === line || highlight.position.end.line === line)) {
highlight.currentSourceLocation(null)
this.highlighters[from].splice(index, 1)
}
}
}
}
}

@ -46,7 +46,7 @@ const profile = {
name: 'editor',
description: 'service - editor',
version: packageJson.version,
methods: ['highlight', 'discardHighlight', 'clearAnnotations', 'addAnnotation']
methods: ['highlight', 'discardHighlight', 'discardHighlightAt', 'clearAnnotations', 'addAnnotation']
}
class Editor extends Plugin {
@ -202,6 +202,16 @@ class Editor extends Plugin {
this.sourceHighlighters.discardHighlight(from)
}
discardHighlightAt (line, filePath) {
const { from } = this.currentRequest
this.sourceHighlighters.discardHighlightAt(line, filePath, from)
}
currentHighlights () {
const { from } = this.currentRequest
return this.sourceHighlighters.currentHighlights(from)
}
setTheme (type) {
this.editor.setTheme('ace/theme/' + this._themes[type])
}

@ -13,6 +13,7 @@ class SourceHighlighter {
fileManager: this._components.registry.get('filemanager').api,
compilerArtefacts: this._components.registry.get('compilersartefacts').api
}
this.position = null
this.statementMarker = null
this.fullLineMarker = null
this.source = null
@ -61,7 +62,7 @@ class SourceHighlighter {
this.statementMarker = this._deps.editor.addMarker(lineColumnPos, this.source, css.highlightcode.className + ' ' + css.customBackgroundColor.className)
this._deps.editor.scrollToLine(lineColumnPos.start.line, true, true, function () {})
this.position = lineColumnPos
if (lineColumnPos.start.line === lineColumnPos.end.line) {
this.fullLineMarker = this._deps.editor.addMarker({
start: {

@ -70,6 +70,12 @@ module.exports = {
.checkElementStyle('.ace_comment.ace_doc', 'color', aceThemes.dark.comment)
.checkElementStyle('.ace_function', 'color', aceThemes.dark.function)
.checkElementStyle('.ace_variable', 'color', aceThemes.dark.variable)
},
'Should highlight source code': function (browser) {
browser.addFile('browser/sourcehighlight.js', sourcehighlightScript)
.switchFile('browser/sourcehighlight.js')
.executeScript('remix.exeCurrent()')
.end()
},
@ -90,3 +96,47 @@ var aceThemes = {
variable: 'rgb(153, 119, 68)'
}
}
const sourcehighlightScript = `
(async () => {
try {
const pos = {
start: {
line: 32,
column: 3
},
end: {
line: 32,
column: 20
}
}
await remix.call('editor', 'highlight', pos, 'browser/3_Ballot.sol')
const pos2 = {
start: {
line: 40,
column: 3
},
end: {
line: 40,
column: 20
}
}
await remix.call('editor', 'highlight', pos2, 'browser/3_Ballot.sol')
const pos3 = {
start: {
line: 50,
column: 3
},
end: {
line: 50,
column: 20
}
}
await remix.call('editor', 'highlight', pos3, 'browser/3_Ballot.sol')
} catch (e) {
console.log(e.message)
}
})()
`

Loading…
Cancel
Save