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

Commit e7fad07

Browse files
darkwingjasonLaster
authored andcommitted
Store the breakpoint text (#5823)
* Preserve breakpoint text from initial creation * tweaks
1 parent 74520c1 commit e7fad07

File tree

8 files changed

+67
-29
lines changed

8 files changed

+67
-29
lines changed

src/actions/breakpoints/addBreakpoint.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from "../../utils/breakpoint";
1212
import { getSource, getSymbols } from "../../selectors";
1313
import { getGeneratedLocation } from "../../utils/source-maps";
14+
import { getTextAtPosition } from "../../utils/source";
1415

1516
export default async function addBreakpoint(
1617
getState,
@@ -19,8 +20,8 @@ export default async function addBreakpoint(
1920
breakpoint
2021
) {
2122
const state = getState();
22-
2323
const source = getSource(state, breakpoint.location.sourceId);
24+
2425
const location = { ...breakpoint.location, sourceUrl: source.url };
2526
const generatedLocation = await getGeneratedLocation(
2627
state,
@@ -29,6 +30,8 @@ export default async function addBreakpoint(
2930
sourceMaps
3031
);
3132

33+
const generatedSource = getSource(state, generatedLocation.sourceId);
34+
3235
assertLocation(location);
3336
assertLocation(generatedLocation);
3437

@@ -52,6 +55,9 @@ export default async function addBreakpoint(
5255
const symbols = getSymbols(getState(), source);
5356
const astLocation = await getASTLocation(source, symbols, newLocation);
5457

58+
const originalText = getTextAtPosition(source, location);
59+
const text = getTextAtPosition(generatedSource, actualLocation);
60+
5561
const newBreakpoint = {
5662
id,
5763
disabled: false,
@@ -61,7 +67,9 @@ export default async function addBreakpoint(
6167
location: newLocation,
6268
astLocation,
6369
hitCount,
64-
generatedLocation: newGeneratedLocation
70+
generatedLocation: newGeneratedLocation,
71+
text,
72+
originalText
6573
};
6674

6775
assertBreakpoint(newBreakpoint);

src/actions/breakpoints/syncBreakpoint.js

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from "../../utils/breakpoint";
1313

1414
import { getGeneratedLocation } from "../../utils/source-maps";
15+
import { getTextAtPosition } from "../../utils/source";
1516
import { originalToGeneratedId } from "devtools-source-map";
1617
import { getSource } from "../../selectors";
1718
import type {
@@ -50,9 +51,17 @@ function createSyncData(
5051
pendingBreakpoint: PendingBreakpoint,
5152
location: Location,
5253
generatedLocation: Location,
53-
previousLocation: Location
54+
previousLocation: Location,
55+
text: string,
56+
originalText: string
5457
): BreakpointSyncData {
55-
const overrides = { ...pendingBreakpoint, generatedLocation, id };
58+
const overrides = {
59+
...pendingBreakpoint,
60+
generatedLocation,
61+
id,
62+
text,
63+
originalText
64+
};
5665
const breakpoint = createBreakpoint(location, overrides);
5766

5867
assertBreakpoint(breakpoint);
@@ -71,10 +80,13 @@ export async function syncClientBreakpoint(
7180
assertPendingBreakpoint(pendingBreakpoint);
7281

7382
const source = getSource(getState(), sourceId);
83+
7484
const generatedSourceId = sourceMaps.isOriginalId(sourceId)
7585
? originalToGeneratedId(sourceId)
7686
: sourceId;
7787

88+
const generatedSource = getSource(getState(), generatedSourceId);
89+
7890
const { location, astLocation } = pendingBreakpoint;
7991
const previousLocation = { ...location, sourceId };
8092

@@ -110,12 +122,17 @@ export async function syncClientBreakpoint(
110122
// send update only to redux
111123
if (pendingBreakpoint.disabled || (existingClient && isSameLocation)) {
112124
const id = pendingBreakpoint.disabled ? "" : existingClient.id;
125+
const originalText = getTextAtPosition(source, previousLocation);
126+
const text = getTextAtPosition(generatedSource, generatedLocation);
127+
113128
return createSyncData(
114129
id,
115130
pendingBreakpoint,
116131
scopedLocation,
117132
scopedGeneratedLocation,
118-
previousLocation
133+
previousLocation,
134+
text,
135+
originalText
119136
);
120137
}
121138

@@ -145,11 +162,16 @@ export async function syncClientBreakpoint(
145162
newGeneratedLocation
146163
);
147164

165+
const originalText = getTextAtPosition(source, newLocation);
166+
const text = getTextAtPosition(generatedSource, newGeneratedLocation);
167+
148168
return createSyncData(
149169
id,
150170
pendingBreakpoint,
151171
newLocation,
152172
newGeneratedLocation,
153-
previousLocation
173+
previousLocation,
174+
text,
175+
originalText
154176
);
155177
}

src/actions/breakpoints/tests/__snapshots__/syncing.spec.js.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Object {
2626
"sourceId": "magic.js",
2727
"sourceUrl": "http://localhost:8000/examples/magic.js",
2828
},
29+
"originalText": "",
2930
"text": "",
3031
},
3132
"previousLocation": Object {
@@ -63,6 +64,7 @@ Object {
6364
"sourceId": "magic.js",
6465
"sourceUrl": "http://localhost:8000/examples/magic.js",
6566
},
67+
"originalText": "",
6668
"text": "",
6769
},
6870
"previousLocation": Object {
@@ -125,6 +127,7 @@ Object {
125127
"sourceId": "magic.js",
126128
"sourceUrl": "http://localhost:8000/examples/magic.js",
127129
},
130+
"originalText": "",
128131
"text": "",
129132
},
130133
"previousLocation": Object {
@@ -162,6 +165,7 @@ Object {
162165
"sourceId": "magic.js",
163166
"sourceUrl": "http://localhost:8000/magic.js",
164167
},
168+
"originalText": "",
165169
"text": "",
166170
},
167171
"previousLocation": Object {

src/actions/tests/__snapshots__/breakpoints.spec.js.snap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Object {
2626
"sourceId": "a",
2727
"sourceUrl": "http://localhost:8000/examples/a",
2828
},
29+
"originalText": "",
30+
"text": "",
2931
}
3032
`;
3133

@@ -56,5 +58,7 @@ Object {
5658
"sourceId": "a.js/originalSource-d6d70368d5c252598541e693a7ad6c27",
5759
"sourceUrl": "http://localhost:8000/examples/a.js:formatted",
5860
},
61+
"originalText": "function a() {",
62+
"text": "function a() {",
5963
}
6064
`;

src/components/SecondaryPanes/Breakpoints.css

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,6 @@ html .breakpoints-list .breakpoint.paused {
8383
order: 3;
8484
}
8585

86-
:root.theme-light .breakpoint-snippet,
87-
:root.theme-firebug .breakpoint-snippet {
88-
color: var(--theme-comment);
89-
}
90-
91-
:root.theme-dark .breakpoint-snippet {
92-
color: var(--theme-body-color);
93-
opacity: 0.6;
94-
}
95-
96-
.breakpoint-snippet {
97-
overflow: hidden;
98-
text-overflow: ellipsis;
99-
padding-inline-start: 18px;
100-
padding-inline-end: 18px;
101-
}
102-
10386
.breakpoint .close-btn {
10487
position: absolute;
10588
offset-inline-end: 13px;

src/components/SecondaryPanes/Breakpoints.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ class Breakpoints extends Component<Props> {
115115
}
116116

117117
renderBreakpoint(breakpoint) {
118-
const snippet = breakpoint.text || "";
119118
const locationId = breakpoint.locationId;
120119
const line = breakpoint.location.line;
121120
const column = breakpoint.location.column;
@@ -152,7 +151,6 @@ class Breakpoints extends Component<Props> {
152151
<label className="breakpoint-label" title={breakpoint.text}>
153152
{renderSourceLocation(breakpoint.location.source, line, column)}
154153
</label>
155-
<div className="breakpoint-snippet">{snippet}</div>
156154
<CloseButton
157155
handleClick={ev => this.removeBreakpoint(ev, breakpoint)}
158156
tooltip={L10N.getStr("breakpoints.removeBreakpointTooltip")}

src/utils/breakpoint/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ export function createBreakpoint(
117117
hidden,
118118
generatedLocation,
119119
astLocation,
120-
id
120+
id,
121+
text,
122+
originalText
121123
} = overrides;
122124

123125
const defaultASTLocation = { name: undefined, offset: location };
@@ -127,10 +129,11 @@ export function createBreakpoint(
127129
disabled: disabled || false,
128130
hidden: hidden || false,
129131
loading: false,
130-
text: "",
131132
astLocation: astLocation || defaultASTLocation,
132133
generatedLocation: generatedLocation || location,
133-
location
134+
location,
135+
text,
136+
originalText
134137
};
135138

136139
return properties;

src/utils/source.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { basename } from "./path";
1616
import { parse as parseURL } from "url";
1717
export { isMinified } from "./isMinified";
1818

19-
import type { Source, SourceRecord } from "../types";
19+
import type { Source, SourceRecord, Location } from "../types";
2020
import type { SymbolDeclarations } from "../workers/parser";
2121

2222
type transformUrlCallback = string => string;
@@ -313,3 +313,19 @@ export function isLoaded(source: SourceRecord) {
313313
export function isLoading(source: SourceRecord) {
314314
return source.get("loadedState") === "loading";
315315
}
316+
317+
export function getTextAtPosition(source: Source, location: Location) {
318+
if (!source || !source.text) {
319+
return "";
320+
}
321+
322+
const line = location.line;
323+
const column = location.column || 0;
324+
325+
const lineText = source.text.split("\n")[line - 1];
326+
if (!lineText) {
327+
return "";
328+
}
329+
330+
return lineText.slice(column, column + 100).trim();
331+
}

0 commit comments

Comments
 (0)