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
165 lines (137 loc) · 4.16 KB
/
Copy pathBreakpoint.js
File metadata and controls
165 lines (137 loc) · 4.16 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
/* 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 React, { Component } from "react";
import ReactDOM from "react-dom";
import classnames from "classnames";
import CloseButton from "../shared/Button/Close";
import { createEditor } from "../../utils/breakpoint";
import { features } from "../../utils/prefs";
import type { LocalBreakpoint } from "./Breakpoints";
import type SourceEditor from "../../utils/editor/source-editor";
type Props = {
breakpoint: LocalBreakpoint,
onClick: Function,
onContextMenu: Function,
onChange: Function,
onCloseClick: Function
};
function getBreakpointLocation(source, line, column) {
const isWasm = source && source.isWasm;
const columnVal = features.columnBreakpoints && column ? `:${column}` : "";
const bpLocation = isWasm
? `0x${line.toString(16).toUpperCase()}`
: `${line}${columnVal}`;
return bpLocation;
}
class Breakpoint extends Component<Props> {
editor: SourceEditor;
componentDidMount() {
this.setupEditor();
}
componentDidUpdate() {
this.setupEditor();
}
componentWillUnmount() {
if (this.editor) {
this.editor.destroy();
}
}
shouldComponentUpdate(nextProps: Props) {
const prevBreakpoint = this.props.breakpoint;
const nextBreakpoint = nextProps.breakpoint;
return (
!prevBreakpoint ||
(prevBreakpoint.text != nextBreakpoint.text ||
prevBreakpoint.disabled != nextBreakpoint.disabled ||
prevBreakpoint.condition != nextBreakpoint.condition ||
prevBreakpoint.hidden != nextBreakpoint.hidden ||
prevBreakpoint.isCurrentlyPaused != nextBreakpoint.isCurrentlyPaused)
);
}
getBreakpointText() {
const { breakpoint } = this.props;
return breakpoint.condition || breakpoint.text;
}
setupEditor() {
if (this.editor) {
return;
}
this.editor = createEditor(this.getBreakpointText());
// disables the default search shortcuts
// $FlowIgnore
this.editor._initShortcuts = () => {};
const node = ReactDOM.findDOMNode(this);
if (node instanceof HTMLElement) {
const mountNode = node.querySelector(".breakpoint-label");
if (node instanceof HTMLElement) {
// $FlowIgnore
mountNode.innerHTML = "";
this.editor.appendToLocalElement(mountNode);
this.editor.codeMirror.on("mousedown", (_, e) => e.preventDefault());
}
}
}
renderCheckbox() {
const { onChange, breakpoint } = this.props;
const { disabled } = breakpoint;
return (
<input
type="checkbox"
className="breakpoint-checkbox"
checked={!disabled}
onChange={onChange}
onClick={ev => ev.stopPropagation()}
/>
);
}
renderText() {
const text = this.getBreakpointText();
return (
<label className="breakpoint-label" title={text}>
{text}
</label>
);
}
renderLineClose() {
const { breakpoint, onCloseClick } = this.props;
const { line, column } = breakpoint.location;
return (
<div className="breakpoint-line-close">
<div className="breakpoint-line">
{getBreakpointLocation(breakpoint.source, line, column)}
</div>
<CloseButton
handleClick={onCloseClick}
tooltip={L10N.getStr("breakpoints.removeBreakpointTooltip")}
/>
</div>
);
}
render() {
const { breakpoint, onClick, onContextMenu } = this.props;
const locationId = breakpoint.locationId;
const isCurrentlyPaused = breakpoint.isCurrentlyPaused;
const isDisabled = breakpoint.disabled;
const isConditional = !!breakpoint.condition;
return (
<div
className={classnames({
breakpoint,
paused: isCurrentlyPaused,
disabled: isDisabled,
"is-conditional": isConditional
})}
key={locationId}
onClick={onClick}
onContextMenu={onContextMenu}
>
{this.renderCheckbox()}
{this.renderText()}
{this.renderLineClose()}
</div>
);
}
}
export default Breakpoint;