-
Notifications
You must be signed in to change notification settings - Fork 949
Expand file tree
/
Copy pathproblems.js
More file actions
97 lines (83 loc) · 2.18 KB
/
problems.js
File metadata and controls
97 lines (83 loc) · 2.18 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
import "./style.scss";
import Page from "components/page";
import actionStack from "lib/actionStack";
import EditorFile from "lib/editorFile";
import helpers from "utils/helpers";
export default function Problems() {
const $page = Page(strings["problems"]);
/**@type {EditorFile[]} */
const files = editorManager.files;
const $content = <div id="problems"></div>;
files.forEach((file) => {
if (file.type !== "editor") return;
/**@type {[]} */
const annotations = file.session?.getAnnotations();
if (!annotations.length) return;
$content.append(
<details open="true" className="single-file">
<summary>{`${file.name} (${annotations.length})`}</summary>
<div className="problems">
{annotations.map((annotation) => {
let icon = "info";
switch (annotation.type) {
case "error":
icon = "cancel";
break;
case "warning":
icon = "warningreport_problem";
break;
default:
break;
}
return (
<div
className="problem"
data-action="goto"
data-file-id={file.id}
annotation={annotation}
>
<span className={`icon ${icon}`}></span>
<span data-type={annotation.type} className="problem-message">
{annotation.text}
</span>
<span className="problem-line">
{annotation.row + 1}:{annotation.column + 1}
</span>
</div>
);
})}
</div>
</details>,
);
});
$content.addEventListener("click", clickHandler);
$page.body = $content;
app.append($page);
helpers.showAd();
$page.onhide = function () {
helpers.hideAd();
actionStack.remove("problems");
};
actionStack.push({
id: "problems",
action: $page.hide,
});
/**
* Click handler for problems page
* @param {MouseEvent} e
*/
function clickHandler(e) {
const $target = e.target;
const { action } = $target.dataset;
if (action === "goto") {
const { fileId } = $target.dataset;
const annotation = $target.annotation;
editorManager.switchFile(fileId);
editorManager.editor.gotoLine(annotation.row + 1, annotation.column);
$page.hide();
setTimeout(() => {
editorManager.editor.focus();
}, 100);
}
}
}