forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
176 lines (147 loc) · 4.24 KB
/
index.js
File metadata and controls
176 lines (147 loc) · 4.24 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// @flow
import { isEnabled } from "devtools-config";
import * as sourceDocumentUtils from "./source-documents";
import { shouldPrettyPrint } from "../../utils/source";
import * as expressionUtils from "./expression.js";
import * as sourceSearchUtils from "./source-search";
const { findNext, findPrev } = sourceSearchUtils;
import { isWasm, lineToWasmOffset, wasmOffsetToLine } from "../wasm";
import { SourceEditor, SourceEditorUtils } from "devtools-source-editor";
import type { AstPosition, AstLocation } from "../../workers/parser/types";
import type { EditorPosition, EditorRange } from "../editor/types";
function shouldShowPrettyPrint(selectedSource) {
if (!selectedSource) {
return false;
}
selectedSource = selectedSource.toJS();
return shouldPrettyPrint(selectedSource);
}
function shouldShowFooter(selectedSource, horizontal) {
if (!horizontal) {
return true;
}
return shouldShowPrettyPrint(selectedSource);
}
function traverseResults(e, ctx, query, dir, modifiers) {
e.stopPropagation();
e.preventDefault();
if (dir == "prev") {
findPrev(ctx, query, true, modifiers);
} else if (dir == "next") {
findNext(ctx, query, true, modifiers);
}
}
function createEditor() {
const gutters = ["breakpoints", "hit-markers", "CodeMirror-linenumbers"];
if (isEnabled("codeFolding")) {
gutters.push("CodeMirror-foldgutter");
}
return new SourceEditor({
mode: "javascript",
foldGutter: isEnabled("codeFolding"),
enableCodeFolding: isEnabled("codeFolding"),
readOnly: true,
lineNumbers: true,
theme: "mozilla",
styleActiveLine: false,
lineWrapping: false,
matchBrackets: true,
showAnnotationRuler: true,
gutters,
value: " ",
extraKeys: {
// Override code mirror keymap to avoid conflicts with split console.
Esc: false,
"Cmd-F": false,
"Cmd-G": false
}
});
}
function toEditorLine(sourceId: string, lineOrOffset: number): ?number {
return isWasm(sourceId)
? wasmOffsetToLine(sourceId, lineOrOffset)
: lineOrOffset - 1;
}
function toEditorPosition(
sourceId: string,
location: AstPosition
): EditorPosition {
return {
line: toEditorLine(sourceId, location.line),
column: isWasm(sourceId) ? 0 : location.column
};
}
function toEditorRange(sourceId: string, location: AstLocation): EditorRange {
const { start, end } = location;
return {
start: toEditorPosition(sourceId, start),
end: toEditorPosition(sourceId, end)
};
}
function toSourceLine(sourceId: string, line: number): ?number {
return isWasm(sourceId) ? lineToWasmOffset(sourceId, line) : line + 1;
}
function scrollToColumn(codeMirror: any, line: number, column: number) {
const { top, left } = codeMirror.charCoords(
{ line: line, ch: column },
"local"
);
const centeredX = left - codeMirror.getScrollerElement().offsetWidth / 2;
const centeredY = top - codeMirror.getScrollerElement().offsetHeight / 2;
codeMirror.scrollTo(centeredX, centeredY);
}
function toSourceLocation(
sourceId: string,
location: EditorPosition
): AstPosition {
return {
line: toSourceLine(sourceId, location.line),
column: isWasm(sourceId) ? undefined : location.column
};
}
function markText(editor: any, className, location: EditorRange) {
const { start, end } = location;
return editor.codeMirror.markText(
{ ch: start.column, line: start.line },
{ ch: end.column, line: end.line },
{ className }
);
}
function lineAtHeight(editor, sourceId, event) {
const editorLine = editor.codeMirror.lineAtHeight(event.clientY);
return toSourceLine(sourceId, editorLine);
}
function getSourceLocationFromMouseEvent(editor, selectedLocation, e) {
const { line, ch } = editor.codeMirror.coordsChar({
left: e.clientX,
top: e.clientY
});
return {
sourceId: selectedLocation.sourceId,
line: line + 1,
column: ch + 1
};
}
module.exports = Object.assign(
{},
expressionUtils,
sourceDocumentUtils,
sourceSearchUtils,
SourceEditorUtils,
{
createEditor,
isWasm,
toEditorLine,
toEditorPosition,
toEditorRange,
toSourceLine,
scrollToColumn,
toSourceLocation,
shouldShowPrettyPrint,
shouldShowFooter,
traverseResults,
markText,
lineAtHeight,
getSourceLocationFromMouseEvent
}
);