diff --git a/mix/qml/html/cm/errorannotation.js b/mix/qml/html/cm/errorannotation.js new file mode 100644 index 000000000..4da65ffa0 --- /dev/null +++ b/mix/qml/html/cm/errorannotation.js @@ -0,0 +1,46 @@ +function ErrorAnnotation(editor, line, col, content) +{ + this.opened = false; + this.line = line; + this.col = col; + this.content = content; + this.editor = editor; + this.errorMark = null; + this.lineWidget = null; + this.init(); + this.open(); +} + +ErrorAnnotation.prototype.init = function() +{ + var separators = [' ', '\\\+', '-', ';', '\\\(', '\\\{', '\\\}', '\\\)', '\\*', '/', ':', '\\\?']; + var errorPart = editor.getLine(this.line).substring(this.col); + var incrMark = this.col + errorPart.split(new RegExp(separators.join('|'), 'g'))[0].length; + if (incrMark === this.col) + incrMark = this.col + 1; + this.errorMark = editor.markText({ line: this.line, ch: this.col }, { line: this.line, ch: incrMark }, { className: "CodeMirror-errorannotation", inclusiveRight: true }); +} + +ErrorAnnotation.prototype.open = function() +{ + var node = document.createElement("div"); + node.id = "annotation" + node.innerHTML = this.content; + node.className = "CodeMirror-errorannotation-context" + this.lineWidget = this.editor.addLineWidget(this.errorMark.find().from.line, node, { coverGutter: true }); + this.opened = true; +} + +ErrorAnnotation.prototype.close = function() +{ + this.lineWidget.clear(); + this.opened = false; +} + +ErrorAnnotation.prototype.detroy = function() +{ + if (this.opened) + this.close(); + if (this.errorMark) + this.errorMark.clear(); +} diff --git a/mix/qml/html/cm/solarized.css b/mix/qml/html/cm/solarized.css index 9f324241a..8a15b731f 100644 --- a/mix/qml/html/cm/solarized.css +++ b/mix/qml/html/cm/solarized.css @@ -171,6 +171,15 @@ view-port /* Error annotation */ .CodeMirror-errorannotation { - background: red; + background: rgb(255, 255, 170); + color: red !important; +} + +.CodeMirror-errorannotation-context { + font-family: monospace; + font-size: small; + color: red; + background: rgb(255, 255, 170); + padding: 2px; } diff --git a/mix/qml/html/codeeditor.html b/mix/qml/html/codeeditor.html index 4545b6239..5a8d5c462 100644 --- a/mix/qml/html/codeeditor.html +++ b/mix/qml/html/codeeditor.html @@ -22,6 +22,7 @@ + diff --git a/mix/qml/html/codeeditor.js b/mix/qml/html/codeeditor.js index ea04f891b..a549d0e68 100644 --- a/mix/qml/html/codeeditor.js +++ b/mix/qml/html/codeeditor.js @@ -134,14 +134,12 @@ isClean = function() return editor.isClean(changeId); } -var errorMark; +var annotation = null; var compilationCompleteBool = true; compilationError = function(line, column, content) { compilationCompleteBool = false; window.setTimeout(function(){ - if (errorMark) - errorMark.clear(); if (compilationCompleteBool) return; line = parseInt(line); @@ -150,19 +148,17 @@ compilationError = function(line, column, content) line = line - 1; if (column > 0) column = column - 1; - - var separators = [' ', '\\\+', '-', ';', '\\\(', '\\\{', '\\\}', '\\\)', '\\*', '/', ':', '\\\?']; - var errorPart = editor.getLine(line).substring(column); - var incrMark = column + errorPart.split(new RegExp(separators.join('|'), 'g'))[0].length; - if (incrMark === column) - incrMark = column + 1; - errorMark = editor.markText({ line: line, ch: column }, { line: line, ch: incrMark }, { className: "CodeMirror-errorannotation" }); - }, 1000) + if (annotation == null) + annotation = new ErrorAnnotation(editor, line, column, content); + }, 500) } compilationComplete = function() { - if (errorMark) - errorMark.clear(); + if (annotation !== null) + { + annotation.detroy(); + annotation = null; + } compilationCompleteBool = true; } diff --git a/mix/web.qrc b/mix/web.qrc index 118177d07..10cd26764 100644 --- a/mix/web.qrc +++ b/mix/web.qrc @@ -27,5 +27,6 @@ qml/html/cm/closebrackets.js qml/html/cm/solidityToken.js qml/html/cm/javascript-hint.js + qml/html/cm/errorannotation.js