Browse Source

error annotation widget

cl-refactor
yann300 10 years ago
parent
commit
28ccaf0cfa
  1. 46
      mix/qml/html/cm/errorannotation.js
  2. 11
      mix/qml/html/cm/solarized.css
  3. 1
      mix/qml/html/codeeditor.html
  4. 22
      mix/qml/html/codeeditor.js
  5. 1
      mix/web.qrc

46
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();
}

11
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;
}

1
mix/qml/html/codeeditor.html

@ -22,6 +22,7 @@
<script src="cm/javascript-hint.js"></script>
<script src="cm/anyword-hint.js"></script>
<script src="cm/closebrackets.js"></script>
<script src="cm/errorannotation.js"></script>
<body oncontextmenu="return false;"></body>
<script src="codeeditor.js"></script>

22
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;
}

1
mix/web.qrc

@ -27,5 +27,6 @@
<file>qml/html/cm/closebrackets.js</file>
<file>qml/html/cm/solidityToken.js</file>
<file>qml/html/cm/javascript-hint.js</file>
<file>qml/html/cm/errorannotation.js</file>
</qresource>
</RCC>

Loading…
Cancel
Save