Browse Source

small changes

cl-refactor
yann300 10 years ago
parent
commit
433f47b109
  1. 18
      mix/qml/html/cm/errorannotation.js
  2. 8
      mix/qml/html/cm/solarized.css
  3. 8
      mix/qml/html/codeeditor.js

18
mix/qml/html/cm/errorannotation.js

@ -1,8 +1,8 @@
function ErrorAnnotation(editor, line, col, content) function ErrorAnnotation(editor, line, column, content)
{ {
this.opened = false; this.opened = false;
this.line = line; this.line = line;
this.col = col; this.column = column;
this.content = content; this.content = content;
this.editor = editor; this.editor = editor;
this.errorMark = null; this.errorMark = null;
@ -14,11 +14,11 @@ function ErrorAnnotation(editor, line, col, content)
ErrorAnnotation.prototype.init = function() ErrorAnnotation.prototype.init = function()
{ {
var separators = [' ', '\\\+', '-', ';', '\\\(', '\\\{', '\\\}', '\\\)', '\\*', '/', ':', '\\\?']; var separators = [' ', '\\\+', '-', ';', '\\\(', '\\\{', '\\\}', '\\\)', '\\*', '/', ':', '\\\?'];
var errorPart = editor.getLine(this.line).substring(this.col); var errorPart = editor.getLine(this.line).substring(this.column);
var incrMark = this.col + errorPart.split(new RegExp(separators.join('|'), 'g'))[0].length; var incrMark = this.column + errorPart.split(new RegExp(separators.join('|'), 'g'))[0].length;
if (incrMark === this.col) if (incrMark === this.column)
incrMark = this.col + 1; incrMark = this.column + 1;
this.errorMark = editor.markText({ line: this.line, ch: this.col }, { line: this.line, ch: incrMark }, { className: "CodeMirror-errorannotation", inclusiveRight: true }); this.errorMark = editor.markText({ line: this.line, ch: this.column }, { line: this.line, ch: incrMark }, { className: "CodeMirror-errorannotation", inclusiveRight: true });
} }
ErrorAnnotation.prototype.open = function() ErrorAnnotation.prototype.open = function()
@ -26,7 +26,7 @@ ErrorAnnotation.prototype.open = function()
var node = document.createElement("div"); var node = document.createElement("div");
node.id = "annotation" node.id = "annotation"
node.innerHTML = this.content; node.innerHTML = this.content;
node.className = "CodeMirror-errorannotation-context" node.className = "CodeMirror-errorannotation-context";
this.lineWidget = this.editor.addLineWidget(this.errorMark.find().from.line, node, { coverGutter: true }); this.lineWidget = this.editor.addLineWidget(this.errorMark.find().from.line, node, { coverGutter: true });
this.opened = true; this.opened = true;
} }
@ -37,7 +37,7 @@ ErrorAnnotation.prototype.close = function()
this.opened = false; this.opened = false;
} }
ErrorAnnotation.prototype.detroy = function() ErrorAnnotation.prototype.destroy = function()
{ {
if (this.opened) if (this.opened)
this.close(); this.close();

8
mix/qml/html/cm/solarized.css

@ -171,15 +171,15 @@ view-port
/* Error annotation */ /* Error annotation */
.CodeMirror-errorannotation { .CodeMirror-errorannotation {
background: rgb(255, 255, 170); background: #b58900;
color: red !important; color: #dc322f !important;
} }
.CodeMirror-errorannotation-context { .CodeMirror-errorannotation-context {
font-family: monospace; font-family: monospace;
font-size: small; font-size: small;
color: red; color: #dc322f;
background: rgb(255, 255, 170); background: #b58900;
padding: 2px; padding: 2px;
} }

8
mix/qml/html/codeeditor.js

@ -148,8 +148,14 @@ compilationError = function(line, column, content)
line = line - 1; line = line - 1;
if (column > 0) if (column > 0)
column = column - 1; column = column - 1;
if (annotation == null) if (annotation == null)
annotation = new ErrorAnnotation(editor, line, column, content); annotation = new ErrorAnnotation(editor, line, column, content);
else if (annotation.line !== line || annotation.column !== column || annotation.content !== content)
{
annotation.destroy();
annotation = new ErrorAnnotation(editor, line, column, content);
}
}, 500) }, 500)
} }
@ -157,7 +163,7 @@ compilationComplete = function()
{ {
if (annotation !== null) if (annotation !== null)
{ {
annotation.detroy(); annotation.destroy();
annotation = null; annotation = null;
} }
compilationCompleteBool = true; compilationCompleteBool = true;

Loading…
Cancel
Save