Repository navigation
Expand file tree
/
Copy pathdecorate.js
More file actions
121 lines (103 loc) · 3.87 KB
/
Copy pathdecorate.js
File metadata and controls
121 lines (103 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*jslint plusplus: true, vars: true, nomen: true */
/*global define, brackets, console, setTimeout, $, document, alert */
define(function (require, exports, module) {
"use strict";
var DocumentManager = brackets.getModule("document/DocumentManager");
var curOpenDir,
curOpenFile,
curOpenLang;
function make_gutter() {
/*
var cm = DocumentManager.getCurrentDocument()._masterEditor._codeMirror;
var hasGutter = false;
var i, n;
for (i = 0, n = cm.getOption('gutters'); i < n.length; i++) {
hasGutter = hasGutter || n[i] === 'compiler-gutter';
}
if (!hasGutter) {
cm.setOption('gutters', ["compiler-gutter"].concat(cm.getOption('gutters')));
}
*/
}
function remove_gutter() {
/*
var cm = DocumentManager.getCurrentDocument()._masterEditor._codeMirror;
var opts = [], i, n;
for (i = 0, n = cm.getOption('gutters'); i < n.length; i++) {
if (n[i] !== 'compiler-gutter') { opts.push(n[i]); }
}
cm.setOption('gutters', opts);
cm.clearGutter("compiler-gutter"); //added
*/
}
function add_line_errors(line, msg) {
var dm = DocumentManager.getCurrentDocument()._masterEditor;
var cm = dm._codeMirror;
/*
var e = document.createElement('span');
e.appendChild(document.createTextNode("●●●"));
e.style.color = "red";
e.style.size = 18;
e.style.textAlign = "right";
e.title = msg;
cm.setGutterMarker(line, "compiler-gutter", e);
*/
var doc = cm.getDoc();
var marker = doc.markText({line: line, ch: 0}, {line: line + 1, ch: 0}, {className: "cm-error", clearOnEnter: true, clearWhenEmpty: true, title: msg});
///cm.addLineClass(line, "text", "line-text-error");
/// cm.addLineClass(line, "background", "cm-error");
// cm.addLineClass(line, "text", "cm-keyword");
// cm.addLineClass(line, "text", "CodeMirror-selectedtext");
cm.refresh();
return marker;
}
function setCurrentFile() {
curOpenDir = DocumentManager.getCurrentDocument().file._parentPath;
curOpenFile = DocumentManager.getCurrentDocument().file._path;
curOpenLang = DocumentManager.getCurrentDocument().language._name;
}
function resetFile(lastFileErrors, doc) {
var cm = doc._masterEditor._codeMirror;
var size = cm.doc.size;
var i;
while (lastFileErrors.length > 0) {
var marker = lastFileErrors.pop().marker;
if (marker) { marker.clear(); }
//cm.removeLineClass(i, "background", "cm-error");
//cm.removeLineClass(i, "text", "line-text-error");
}
}
function reset(lastErrors) {
$('.line-text-error').attr('title', "");
remove_gutter();
setCurrentFile(); // TODO: not sure if needed
var docList = DocumentManager.getAllOpenDocuments();
var i;
for (i = 0; i < docList.length; i++) {
var doc = docList[i];
var file_type = doc.language._name;
if (curOpenLang === file_type) {
var file = doc.file._path;
if (lastErrors[file]) {
resetFile(lastErrors[file], doc);
}
}
}
}
function add_errors_to_file(lastErrors) {
setCurrentFile();
// Set Gutter
make_gutter();
// decorate current file
var i,
n = lastErrors[curOpenFile];
for (i = 0; n && i < n.length; i++) {
if (!n[i].marker || !n[i].marker.find()) { n[i].marker = add_line_errors(n[i].line, n[i].error); }
}
}
module.exports = {
setCurrentFile: setCurrentFile,
add_errors_to_file: add_errors_to_file,
reset: reset
};
});