Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.

Commit 8f00c88

Browse files
darkwingjasonLaster
authored andcommitted
Syntax-highlight breakpoints (#5864)
1 parent db286a4 commit 8f00c88

File tree

6 files changed

+110
-4
lines changed

6 files changed

+110
-4
lines changed

src/components/SecondaryPanes/BreakpointItem.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@
44

55
// @flow
66
import React, { Component } from "react";
7+
import ReactDOM from "react-dom";
78
import classnames from "classnames";
89

910
import CloseButton from "../shared/Button/Close";
1011

12+
import { createEditor } from "../../utils/breakpoint";
1113
import { features } from "../../utils/prefs";
14+
1215
import type { LocalBreakpoint } from "./Breakpoints";
16+
import type SourceEditor from "../../utils/editor/source-editor";
1317

1418
type Props = {
1519
breakpoint: LocalBreakpoint,
@@ -30,6 +34,54 @@ function getBreakpointLocation(source, line, column) {
3034
}
3135

3236
class BreakpointItem extends Component<Props> {
37+
editor: SourceEditor;
38+
39+
componentDidMount() {
40+
this.setupEditor();
41+
}
42+
componentDidUpdate() {
43+
this.setupEditor();
44+
}
45+
46+
componentWillUnmount() {
47+
if (this.editor) {
48+
this.editor.destroy();
49+
}
50+
}
51+
52+
shouldComponentUpdate(nextProps: Props) {
53+
const prevBreakpoint = this.props.breakpoint;
54+
const nextBreakpoint = nextProps.breakpoint;
55+
56+
return (
57+
!prevBreakpoint ||
58+
(prevBreakpoint.text != nextBreakpoint.text ||
59+
prevBreakpoint.disabled != nextBreakpoint.disabled ||
60+
prevBreakpoint.condition != nextBreakpoint.condition ||
61+
prevBreakpoint.hidden != nextBreakpoint.hidden ||
62+
prevBreakpoint.isCurrentlyPaused != nextBreakpoint.isCurrentlyPaused)
63+
);
64+
}
65+
66+
setupEditor() {
67+
const { breakpoint } = this.props;
68+
this.editor = createEditor(breakpoint.text);
69+
70+
// disables the default search shortcuts
71+
// $FlowIgnore
72+
this.editor._initShortcuts = () => {};
73+
74+
const node = ReactDOM.findDOMNode(this);
75+
if (node instanceof HTMLElement) {
76+
const mountNode = node.querySelector(".breakpoint-label");
77+
if (node instanceof HTMLElement) {
78+
// $FlowIgnore
79+
mountNode.innerHTML = "";
80+
this.editor.appendToLocalElement(mountNode);
81+
}
82+
}
83+
}
84+
3385
render() {
3486
const {
3587
breakpoint,

src/components/SecondaryPanes/Breakpoints.css

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ html .breakpoints-list .breakpoint.paused {
7474
font-size: 11px;
7575
color: var(--theme-comment);
7676
padding-top: 3px;
77+
padding-inline-end: 2px;
7778
min-width: 14px;
7879
text-align: right;
7980
}
@@ -94,6 +95,7 @@ html[dir="rtl"] .breakpoints-list .breakpoint .breakpoint-line {
9495
max-width: calc(100% - var(--breakpoint-expression-right-clear-space));
9596
display: inline-block;
9697
padding-inline-start: 2px;
98+
padding-inline-end: 8px;
9799
cursor: default;
98100
flex-grow: 1;
99101
text-overflow: ellipsis;
@@ -139,3 +141,27 @@ html[dir="rtl"] .breakpoints-list .breakpoint .breakpoint-line {
139141
.breakpoint:hover .close {
140142
visibility: visible;
141143
}
144+
145+
.CodeMirror.cm-s-mozilla-breakpoint .CodeMirror-lines {
146+
padding: 0;
147+
}
148+
149+
.CodeMirror.cm-s-mozilla-breakpoint .CodeMirror-sizer {
150+
min-width: initial !important;
151+
}
152+
153+
.breakpoints-list .breakpoint.disabled .CodeMirror.cm-s-mozilla-breakpoint {
154+
transition: opacity 0.5s linear;
155+
opacity: 0.5;
156+
}
157+
158+
.CodeMirror.cm-s-mozilla-breakpoint .CodeMirror-line span[role=presentation] {
159+
max-width: 100%;
160+
overflow: hidden;
161+
text-overflow: ellipsis;
162+
display: inline-block;
163+
}
164+
165+
.CodeMirror.cm-s-mozilla-breakpoint .CodeMirror-code {
166+
cursor: default;
167+
}

src/components/SecondaryPanes/Breakpoints.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ class Breakpoints extends Component<Props> {
9999
this.props.removeBreakpoint(breakpoint.location);
100100
}
101101

102-
renderBreakpoint(breakpoint, key) {
102+
renderBreakpoint(breakpoint) {
103103
return (
104104
<BreakpointItem
105-
key={key}
105+
key={breakpoint.locationId}
106106
breakpoint={breakpoint}
107107
onClick={() => this.selectBreakpoint(breakpoint)}
108108
onContextMenu={e =>
@@ -133,8 +133,8 @@ class Breakpoints extends Component<Props> {
133133
{filename}
134134
</div>,
135135
...groupedBreakpoints[filename]
136-
.filter(bp => !bp.hidden)
137-
.map((bp, i) => this.renderBreakpoint(bp, `${filename}-${i}`))
136+
.filter(bp => !bp.hidden && bp.text)
137+
.map((bp, i) => this.renderBreakpoint(bp))
138138
];
139139
})
140140
];
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* This Source Code Form is subject to the terms of the Mozilla Public
2+
* License, v. 2.0. If a copy of the MPL was not distributed with this
3+
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
4+
5+
// @flow
6+
7+
import SourceEditor from "../editor/source-editor";
8+
9+
export function createEditor(value: string) {
10+
return new SourceEditor({
11+
mode: "javascript",
12+
foldGutter: false,
13+
enableCodeFolding: false,
14+
readOnly: "nocursor",
15+
lineNumbers: false,
16+
theme: "mozilla mozilla-breakpoint",
17+
styleActiveLine: false,
18+
lineWrapping: false,
19+
matchBrackets: false,
20+
showAnnotationRuler: false,
21+
gutters: false,
22+
value: value || "",
23+
scrollbarStyle: null
24+
});
25+
}

src/utils/breakpoint/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { getBreakpoint } from "../../selectors";
88
import assert from "../assert";
99
import { features } from "../prefs";
1010

11+
export { createEditor } from "./create-editor";
12+
1113
export { getASTLocation, findScopeByName } from "./astBreakpointLocation";
1214

1315
import type {

webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ function buildConfig(envConfig) {
5757

5858
extra.excludeMap = {
5959
"./source-editor": "devtools/client/sourceeditor/editor",
60+
"../editor/source-editor": "devtools/client/sourceeditor/editor",
6061
"./test-flag": "devtools/shared/flags",
6162
"./fronts-device": "devtools/shared/fronts/device",
6263
react: "devtools/client/shared/vendor/react",

0 commit comments

Comments
 (0)