Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow multiple highlight per plugin #2815

Merged
merged 7 commits into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Added line class to hightlighter
  • Loading branch information
ioedeveloper authored and yann300 committed May 7, 2020
commit 3373887f61d320ce1594ed5faf7ec917727d265b
2 changes: 1 addition & 1 deletion src/app/editor/sourceHighlighter.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class SourceHighlighter {
}
`

this.statementMarker = this._deps.editor.addMarker(lineColumnPos, this.source, css.highlightcode.className + ' ' + css.customBackgroundColor.className)
this.statementMarker = this._deps.editor.addMarker(lineColumnPos, this.source, css.highlightcode.className + ' ' + css.customBackgroundColor.className + ' ' + `highlightLine${lineColumnPos.start.line}`)
this._deps.editor.scrollToLine(lineColumnPos.start.line, true, true, function () {})
this.position = lineColumnPos
if (lineColumnPos.start.line === lineColumnPos.end.line) {
Expand Down
25 changes: 25 additions & 0 deletions test-browser/commands/scrollUp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const EventEmitter = require('events')

class ScrollUp extends EventEmitter {
command (target, height) {
this.api.perform((done) => {
_scrollUp(this.api, target, height, () => {
done()
this.emit('complete')
})
})
return this
}
}

function _scrollUp (browser, target, height, cb) {
browser.execute(function (target, height) {
const element = document.querySelector(target)

element.scrollTop = element.scrollHeight - height
}, [target, height], function () {
cb()
})
}

module.exports = ScrollUp
97 changes: 53 additions & 44 deletions test-browser/tests/editor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,16 @@ module.exports = {
},

'Should highlight source code': function (browser) {
browser.addFile('browser/sourcehighlight.js', sourcehighlightScript)
browser.addFile('sourcehighlight.js', sourcehighlightScript)
.switchFile('browser/sourcehighlight.js')
.executeScript('remix.exeCurrent()')
.scrollUp('*[data-id="editorInput"]', 100)
.pause(5000)
.scrollUp('.ace_scroller', 100)
.waitForElementPresent('.highlightLine32')
.checkElementStyle('.highlightLine32', 'background-color', 'rgb(8, 108, 181)')
.waitForElementPresent('.highlightLine40')
.checkElementStyle('.highlightLine40', 'background-color', 'rgb(8, 108, 181)')
.end()
},

Expand All @@ -97,46 +104,48 @@ var aceThemes = {
}
}

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)
}
})()
`
const sourcehighlightScript = {
content: `
(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)
}
})()
`
}