Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions apps/remix-ide-e2e/src/tests/editor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ module.exports = {
},

'Should highlight source code': function (browser: NightwatchBrowser) {
// include all files here because switching between plugins in side-panel removes highlight
browser.addFile('sourcehighlight.js', sourcehighlightScript)
.addFile('removeSourcehighlightScript.js', removeSourcehighlightScript)
.addFile('removeAllSourcehighlightScript.js', removeAllSourcehighlightScript)
.openFile('browser/sourcehighlight.js')
.executeScript('remix.exeCurrent()')
.editorScroll('down', 60)
Expand All @@ -90,20 +93,26 @@ module.exports = {
},

'Should remove 1 highlight from source code': function (browser: NightwatchBrowser) {
browser.addFile('removeSourcehighlightScript.js', removeSourcehighlightScript)
.openFile('browser/removeSourcehighlightScript.js')
browser.waitForElementVisible('li[key="browser/removeSourcehighlightScript.js"]')
.click('li[key="browser/removeSourcehighlightScript.js"]')
.pause(2000)
.executeScript('remix.exeCurrent()')
.openFile('browser/3_Ballot.sol')
.waitForElementVisible('li[key="browser/3_Ballot.sol"]')
.click('li[key="browser/3_Ballot.sol"]')
.pause(2000)
.waitForElementNotPresent('.highlightLine32')
.checkElementStyle('.highlightLine40', 'background-color', 'rgb(8, 108, 181)')
.checkElementStyle('.highlightLine50', 'background-color', 'rgb(8, 108, 181)')
},

'Should remove all highlights from source code': function (browser: NightwatchBrowser) {
browser.addFile('removeAllSourcehighlightScript.js', removeAllSourcehighlightScript)
.openFile('browser/removeAllSourcehighlightScript.js')
browser.waitForElementVisible('li[key="browser/removeAllSourcehighlightScript.js"]')
.click('li[key="browser/removeAllSourcehighlightScript.js"]')
.pause(2000)
.executeScript('remix.exeCurrent()')
.openFile('browser/3_Ballot.sol')
.waitForElementVisible('li[key="browser/3_Ballot.sol"]')
.click('li[key="browser/3_Ballot.sol"]')
.pause(2000)
.waitForElementNotPresent('.highlightLine32')
.waitForElementNotPresent('.highlightLine40')
.waitForElementNotPresent('.highlightLine50')
Expand Down
6 changes: 6 additions & 0 deletions apps/remix-ide/src/app/components/side-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,13 @@ export class SidePanel extends AbstractPanel {
})
}

focus (name) {
this.emit('focusChanged', name)
}

removeView (profile) {
super.removeView(profile)
this.emit('pluginDisabled', profile.name)
this.verticalIcons.unlinkContent(profile)
}

Expand All @@ -108,6 +113,7 @@ export class SidePanel extends AbstractPanel {
async showContent (name) {
super.showContent(name)
this.renderHeader()
this.focus(name)
}

/** The header of the side panel */
Expand Down
30 changes: 27 additions & 3 deletions apps/remix-ide/src/app/editor/SourceHighlighters.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
'use strict'
const SourceHighlighter = require('./sourceHighlighter')

// EditorApi:
// - methods: ['highlight', 'discardHighlight'],

class SourceHighlighters {

constructor () {
Expand All @@ -28,13 +25,40 @@ class SourceHighlighters {
}
}

// highlights all locations for @from plugin
highlightAllFrom (from) {
try {
if (!this.highlighters[from]) return
const sourceHighlight = new SourceHighlighter()
for (const index in this.highlighters[from]) {
sourceHighlight.currentSourceLocationFromfileName(
this.highlighters[from][index].position,
this.highlighters[from][index].source,
this.highlighters[from][index].style
)
this.highlighters[from][index] = sourceHighlight
}
} catch (e) {
throw e
}
}

discardHighlight (from) {
if (this.highlighters[from]) {
for (const index in this.highlighters[from]) this.highlighters[from][index].currentSourceLocation(null)
}
this.highlighters[from] = []
}

hideHighlightsExcept (toStay) {
for (const highlighter in this.highlighters) {
for (const index in this.highlighters[highlighter]) {
this.highlighters[highlighter][index].currentSourceLocation(null)
}
this.highlightAllFrom(toStay)
}
}

discardHighlightAt (line, filePath, from) {
if (this.highlighters[from]) {
for (const index in this.highlighters[from]) {
Expand Down
7 changes: 4 additions & 3 deletions apps/remix-ide/src/app/editor/contextualListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,15 @@ class ContextualListener extends Plugin {
}

_highlightInternal (position, node) {
if (node.nodeType === 'Block') return
let lastCompilationResult = this._deps.compilersArtefacts['__last']
if (lastCompilationResult && lastCompilationResult.languageversion.indexOf('soljson') === 0) {
let lineColumn = this._deps.offsetToLineColumnConverter.offsetToLineColumn(position, position.file, lastCompilationResult.getSourceCode().sources, lastCompilationResult.getAsts())
const css = csjs`
.highlightref_fullLine {
position:absolute;
z-index:2;
opacity: 0.4;
position: absolute;
z-index: 2;
opacity: 0.1;
background-color: var(--info);
}
`
Expand Down
11 changes: 10 additions & 1 deletion apps/remix-ide/src/app/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,23 @@ class Editor extends Plugin {
this.editor.on('changeSession', () => {
this._onChange()
this.event.trigger('sessionSwitched', [])

this.editor.getSession().on('change', () => {
this._onChange()
this.event.trigger('contentChanged', [])
})
})
}

onActivation () {
this.on('sidePanel', 'focusChanged', (name) => this.sourceHighlighters.hideHighlightsExcept(name))
this.on('sidePanel', 'pluginDisabled', (name) => this.sourceHighlighters.discardHighlight(name))
}

onDeactivation () {
this.off('sidePanel', 'focusChanged')
this.off('sidePanel', 'pluginDisabled')
}

highlight (position, filePath, hexColor) {
const { from } = this.currentRequest
this.sourceHighlighters.highlight(position, filePath, hexColor, from)
Expand Down
8 changes: 5 additions & 3 deletions apps/remix-ide/src/app/editor/sourceHighlighter.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class SourceHighlighter {
this.source = null
if (lineColumnPos) {
this.source = filePath
this.style = style || 'var(--info)'
//if (!this.source) this.source = this._deps.fileManager.currentFile()
if (this._deps.fileManager.currentFile() !== this.source) {
await this._deps.fileManager.open(this.source)
this.source = this._deps.fileManager.currentFile()
Expand All @@ -49,16 +51,16 @@ class SourceHighlighter {
position:absolute;
z-index:20;
opacity: 0.3;
background-color: ${style || 'var(--info)'};
background-color: ${this.style};
}
.highlightcode_fullLine {
position:absolute;
z-index:20;
opacity: 0.5;
background-color: ${style || 'var(--info)'};
background-color: ${this.style};
}
.customBackgroundColor {
background-color: ${style || 'var(--info)'};
background-color: ${this.style};
}
`

Expand Down
2 changes: 1 addition & 1 deletion apps/remix-ide/src/assets/js/editor/darkTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ ace.define("ace/theme/remixDark",["require","exports","module","ace/lib/dom"], f
border: 1px solid #FCE94F;\
}\
.ace-remixDark .ace_marker-layer .ace_active-line {\
background: #363950;\
background: #262843;\
}\
.ace-remixDark .ace_gutter-active-line {\
background-color: #363950;\
Expand Down