Skip to content

Commit fd0c6a7

Browse files
authored
Provide conditional comment styling (firefox-devtools#7377)
1 parent 52f505b commit fd0c6a7

4 files changed

Lines changed: 53 additions & 13 deletions

File tree

src/components/Editor/ColumnBreakpoint.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,22 @@ type Props = {
2626

2727
const breakpointImg = document.createElement("div");
2828
ReactDOM.render(<Svg name={"column-marker"} />, breakpointImg);
29-
function makeBookmark(isActive, { onClick }) {
29+
function makeBookmark(isActive, condition, { onClick }) {
3030
const bp = breakpointImg.cloneNode(true);
3131
const className = isActive ? "active" : "disabled";
32-
bp.className = classnames("column-breakpoint", className);
32+
33+
bp.className = classnames(
34+
"column-breakpoint",
35+
{
36+
"has-condition": condition
37+
},
38+
className
39+
);
40+
if (condition) {
41+
bp.setAttribute("title", condition);
42+
}
3343
bp.onclick = onClick;
44+
3445
return bp;
3546
}
3647

@@ -48,9 +59,14 @@ export default class ColumnBreakpoint extends PureComponent<Props> {
4859
}
4960

5061
const { line, column } = columnBreakpoint.location;
51-
const widget = makeBookmark(columnBreakpoint.enabled, {
52-
onClick: this.toggleBreakpoint
53-
});
62+
const widget = makeBookmark(
63+
columnBreakpoint.enabled,
64+
columnBreakpoint.condition,
65+
{
66+
onClick: this.toggleBreakpoint
67+
}
68+
);
69+
5470
this.bookmark = doc.setBookmark({ line: line - 1, ch: column }, { widget });
5571
};
5672

src/components/Editor/ColumnBreakpoints.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
fill-opacity: 0.5;
2626
}
2727

28+
.column-breakpoint.has-condition svg {
29+
fill: var(--theme-graphs-yellow);
30+
stroke: var(--theme-graphs-orange);
31+
}
32+
2833
.theme-dark .column-breakpoint.active svg {
2934
fill: var(--blue-55);
3035
stroke: var(--blue-40);

src/selectors/test/__snapshots__/visibleColumnBreakpoints.spec.js.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
exports[`visible column breakpoints duplicate generated locations 1`] = `
44
Array [
55
Object {
6+
"condition": undefined,
67
"enabled": true,
78
"location": Object {
89
"column": 1,
910
"line": 1,
1011
},
1112
},
1213
Object {
14+
"condition": null,
1315
"enabled": false,
1416
"location": Object {
1517
"column": 3,
@@ -22,13 +24,15 @@ Array [
2224
exports[`visible column breakpoints ignores single breakpoints 1`] = `
2325
Array [
2426
Object {
27+
"condition": undefined,
2528
"enabled": true,
2629
"location": Object {
2730
"column": 1,
2831
"line": 1,
2932
},
3033
},
3134
Object {
35+
"condition": null,
3236
"enabled": false,
3337
"location": Object {
3438
"column": 3,
@@ -41,13 +45,15 @@ Array [
4145
exports[`visible column breakpoints only shows visible breakpoints 1`] = `
4246
Array [
4347
Object {
48+
"condition": undefined,
4449
"enabled": true,
4550
"location": Object {
4651
"column": 1,
4752
"line": 1,
4853
},
4954
},
5055
Object {
56+
"condition": null,
5157
"enabled": false,
5258
"location": Object {
5359
"column": 3,
@@ -60,13 +66,15 @@ Array [
6066
exports[`visible column breakpoints simple 1`] = `
6167
Array [
6268
Object {
69+
"condition": undefined,
6370
"enabled": true,
6471
"location": Object {
6572
"column": 1,
6673
"line": 1,
6774
},
6875
},
6976
Object {
77+
"condition": null,
7078
"enabled": false,
7179
"location": Object {
7280
"column": 5,

src/selectors/visibleColumnBreakpoints.js

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
44

5-
import { groupBy, hasIn, sortedUniqBy } from "lodash";
5+
import { groupBy, get, sortedUniqBy } from "lodash";
66
import { createSelector } from "reselect";
77

88
import { getViewport } from "../selectors";
@@ -14,7 +14,8 @@ import type { SourceLocation } from "../types";
1414

1515
export type ColumnBreakpoint = {|
1616
+location: SourceLocation,
17-
+enabled: boolean
17+
+enabled: boolean,
18+
+condition: ?string
1819
|};
1920

2021
function contains(location, range) {
@@ -35,9 +36,13 @@ function groupBreakpoints(breakpoints) {
3536
return map;
3637
}
3738

38-
function isEnabled(location, breakpointMap) {
39+
function findBreakpoint(location, breakpointMap) {
3940
const { line, column } = location;
40-
return hasIn(breakpointMap, [line, column]);
41+
const breakpoints = get(breakpointMap, [line, column]);
42+
43+
if (breakpoints) {
44+
return breakpoints[0];
45+
}
4146
}
4247

4348
function getLineCount(columnBreakpoints) {
@@ -101,10 +106,16 @@ export function getColumnBreakpoints(pausePoints, breakpoints, viewport) {
101106
({ location: { line } }) => lineCount[line] > 1
102107
);
103108

104-
return columnBreakpoints.map(({ location }) => ({
105-
location,
106-
enabled: isEnabled(location, breakpointMap)
107-
}));
109+
return columnBreakpoints.map(({ location }) => {
110+
// Find the breakpoint so if we know it's enabled and has condition
111+
const foundBreakpoint = findBreakpoint(location, breakpointMap);
112+
113+
return {
114+
location,
115+
enabled: !!foundBreakpoint,
116+
condition: foundBreakpoint ? foundBreakpoint.condition : null
117+
};
118+
});
108119
}
109120

110121
export const visibleColumnBreakpoints = createSelector(

0 commit comments

Comments
 (0)