forked from firefox-devtools/debugger
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBreakpoint.js
More file actions
172 lines (137 loc) · 4.76 KB
/
Copy pathBreakpoint.js
File metadata and controls
172 lines (137 loc) · 4.76 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
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
// @flow
import { PureComponent } from "react";
import classnames from "classnames";
import { getDocument, toEditorLine } from "../../utils/editor";
import { getSelectedLocation } from "../../utils/selected-location";
import { features } from "../../utils/prefs";
import { showMenu } from "devtools-contextmenu";
import { breakpointItems } from "./menus/breakpoints";
import type { BreakpointItemActions } from "./menus/breakpoints";
import type { EditorItemActions } from "./menus/editor";
import type {
Source,
Breakpoint as BreakpointType,
ThreadContext
} from "../../types";
const breakpointSvg = document.createElement("div");
breakpointSvg.innerHTML =
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 60 15" width="60" height="15"><path d="M53.07.5H1.5c-.54 0-1 .46-1 1v12c0 .54.46 1 1 1h51.57c.58 0 1.15-.26 1.53-.7l4.7-6.3-4.7-6.3c-.38-.44-.95-.7-1.53-.7z"/></svg>';
type Props = {
cx: ThreadContext,
breakpoint: BreakpointType,
selectedSource: Source,
editor: Object,
breakpointActions: BreakpointItemActions,
editorActions: EditorItemActions
};
class Breakpoint extends PureComponent<Props> {
componentDidMount() {
this.addBreakpoint(this.props);
}
componentDidUpdate(prevProps: Props) {
this.removeBreakpoint(prevProps);
this.addBreakpoint(this.props);
}
componentWillUnmount() {
this.removeBreakpoint(this.props);
}
makeMarker() {
const { breakpoint } = this.props;
const bp = breakpointSvg.cloneNode(true);
bp.className = classnames("editor new-breakpoint", {
"breakpoint-disabled": breakpoint.disabled,
"folding-enabled": features.codeFolding
});
bp.onmousedown = this.onClick;
// NOTE: flow does not know about oncontextmenu
(bp: any).oncontextmenu = this.onContextMenu;
return bp;
}
onClick = (event: MouseEvent) => {
const {
cx,
breakpointActions,
editorActions,
breakpoint,
selectedSource
} = this.props;
// ignore right clicks
if ((event.ctrlKey && event.button === 0) || event.button === 2) {
return;
}
event.stopPropagation();
event.preventDefault();
const selectedLocation = getSelectedLocation(breakpoint, selectedSource);
if (event.metaKey) {
return editorActions.continueToHere(cx, selectedLocation.line);
}
if (event.shiftKey) {
if (features.columnBreakpoints) {
return breakpointActions.toggleBreakpointsAtLine(
cx,
!breakpoint.disabled,
selectedLocation.line
);
}
return breakpointActions.toggleDisabledBreakpoint(cx, breakpoint);
}
return breakpointActions.removeBreakpointsAtLine(
cx,
selectedLocation.sourceId,
selectedLocation.line
);
};
onContextMenu = (event: MouseEvent) => {
const { cx, breakpoint, breakpointActions } = this.props;
event.stopPropagation();
event.preventDefault();
showMenu(event, breakpointItems(cx, breakpoint, breakpointActions));
};
addBreakpoint(props: Props) {
const { breakpoint, editor, selectedSource } = props;
const selectedLocation = getSelectedLocation(breakpoint, selectedSource);
// Hidden Breakpoints are never rendered on the client
if (breakpoint.options.hidden) {
return;
}
if (!selectedSource) {
return;
}
const sourceId = selectedSource.id;
const line = toEditorLine(sourceId, selectedLocation.line);
const doc = getDocument(sourceId);
doc.setGutterMarker(line, "breakpoints", this.makeMarker());
editor.codeMirror.addLineClass(line, "line", "new-breakpoint");
editor.codeMirror.removeLineClass(line, "line", "has-condition");
editor.codeMirror.removeLineClass(line, "line", "has-log");
if (breakpoint.options.logValue) {
editor.codeMirror.addLineClass(line, "line", "has-log");
} else if (breakpoint.options.condition) {
editor.codeMirror.addLineClass(line, "line", "has-condition");
}
}
removeBreakpoint(props: Props) {
const { selectedSource, breakpoint } = props;
if (!selectedSource) {
return;
}
const sourceId = selectedSource.id;
const doc = getDocument(sourceId);
if (!doc) {
return;
}
const selectedLocation = getSelectedLocation(breakpoint, selectedSource);
const line = toEditorLine(sourceId, selectedLocation.line);
doc.setGutterMarker(line, "breakpoints", null);
doc.removeLineClass(line, "line", "new-breakpoint");
doc.removeLineClass(line, "line", "has-condition");
doc.removeLineClass(line, "line", "has-log");
}
render() {
return null;
}
}
export default Breakpoint;