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

Commit d32e79e

Browse files
committed
[Preview] stop showing preview for the wrong original files (#5878)
1 parent 0aeeee8 commit d32e79e

File tree

4 files changed

+37
-38
lines changed

4 files changed

+37
-38
lines changed

src/actions/preview.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { getExpressionFromCoords } from "../utils/editor/get-expression";
1414
import {
1515
getPreview,
1616
isLineInScope,
17+
isSelectedFrameVisible,
1718
getSelectedSource,
1819
getSelectedFrame,
1920
getSymbols,
@@ -145,7 +146,10 @@ export function updatePreview(target: HTMLElement, editor: any) {
145146
return;
146147
}
147148

148-
if (!isLineInScope(getState(), tokenPos.line)) {
149+
if (
150+
!isSelectedFrameVisible(getState()) ||
151+
!isLineInScope(getState(), tokenPos.line)
152+
) {
149153
return;
150154
}
151155

src/components/Editor/Preview/index.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ import { debounce } from "lodash";
1010

1111
import Popup from "./Popup";
1212

13-
import {
14-
getPreview,
15-
getSelectedSource,
16-
isSelectedFrameVisible
17-
} from "../../../selectors";
13+
import { getPreview, getSelectedSource } from "../../../selectors";
1814
import actions from "../../../actions";
1915
import { toEditorRange } from "../../../utils/editor";
2016

@@ -69,9 +65,7 @@ class Preview extends PureComponent<Props, State> {
6965

7066
onMouseOver = e => {
7167
const { target } = e;
72-
if (this.props.selectedFrameVisible) {
73-
this.props.updatePreview(target, this.props.editor);
74-
}
68+
this.props.updatePreview(target, this.props.editor);
7569
};
7670

7771
onMouseUp = () => {
@@ -136,8 +130,7 @@ const {
136130
export default connect(
137131
state => ({
138132
preview: getPreview(state),
139-
selectedSource: getSelectedSource(state),
140-
selectedFrameVisible: isSelectedFrameVisible(state)
133+
selectedSource: getSelectedSource(state)
141134
}),
142135
{
143136
addExpression,

src/selectors/isSelectedFrameVisible.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import { originalToGeneratedId, isOriginalId } from "devtools-source-map";
66
import { getSelectedFrame } from "../reducers/pause";
77
import { getSelectedLocation } from "../reducers/sources";
88

9-
function visibleSourceId(location) {
10-
return isOriginalId(location.sourceId)
11-
? originalToGeneratedId(location.sourceId)
12-
: location.sourceId;
9+
function getGeneratedId(sourceId) {
10+
if (isOriginalId(sourceId)) {
11+
return originalToGeneratedId(sourceId);
12+
}
13+
14+
return sourceId;
1315
}
1416

1517
/*
@@ -24,8 +26,12 @@ export function isSelectedFrameVisible(state) {
2426
return false;
2527
}
2628

29+
if (isOriginalId(selectedLocation.sourceId)) {
30+
return selectedLocation.sourceId === selectedFrame.location.sourceId;
31+
}
32+
2733
return (
28-
visibleSourceId(selectedLocation) ===
29-
visibleSourceId(selectedFrame.location)
34+
selectedLocation.sourceId ===
35+
getGeneratedId(selectedFrame.location.sourceId)
3036
);
3137
}

src/test/mochitest/browser_dbg-preview-source-maps.js

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,11 @@
11
/* Any copyright is dedicated to the Public Domain.
22
* http://creativecommons.org/publicdomain/zero/1.0/ */
33

4-
function getCoordsFromPosition(cm, { line, ch }) {
5-
return cm.charCoords({ line: ~~line, ch: ~~ch });
6-
}
74

8-
function hoverAtPos(dbg, { line, ch }) {
9-
info(`Hovering at (${line}, ${ch})\n`);
10-
const cm = getCM(dbg);
11-
const coords = getCoordsFromPosition(cm, { line: line - 1, ch });
12-
const tokenEl = dbg.win.document.elementFromPoint(coords.left, coords.top);
13-
const previewed = waitForDispatch(dbg, "SET_PREVIEW");
14-
tokenEl.dispatchEvent(
15-
new MouseEvent("mouseover", {
16-
bubbles: true,
17-
cancelable: true,
18-
view: dbg.win
19-
})
20-
);
21-
return previewed;
5+
async function assertNoTooltip(dbg) {
6+
await waitForTime(200);
7+
const el = findElement(dbg, "tooltip");
8+
is(el, null, "Tooltip should not exist")
229
}
2310

2411
function assertPreviewTooltip(dbg, { result, expression }) {
@@ -58,12 +45,21 @@ add_task(async function() {
5845
await waitForPaused(dbg);
5946
await waitForSelectedSource(dbg, "times2");
6047

61-
await hoverAtPos(dbg, { line: 2, ch: 9 });
62-
assertPreviewTooltip(dbg, { result: 4, expression: "x" });
48+
info(`Test previewing in the original location`)
49+
await assertPreviews(dbg, [
50+
{ line: 2, column: 10, result: 4, expression: "x" }
51+
]);
6352

53+
info(`Test previewing in the generated location`)
6454
await dbg.actions.jumpToMappedSelectedLocation();
6555
await waitForSelectedSource(dbg, "bundle.js");
56+
await assertPreviews(dbg, [
57+
{ line: 70, column: 11, result: 4, expression: "x" }
58+
]);
59+
6660

67-
await hoverAtPos(dbg, { line: 70, ch: 10 });
68-
assertPreviewTooltip(dbg, { result: 4, expression: "x" });
61+
info(`Test that you can not preview in another original file`);
62+
await selectSource(dbg, "output");
63+
await hoverAtPos(dbg, { line: 2, ch: 16 });
64+
await assertNoTooltip(dbg)
6965
});

0 commit comments

Comments
 (0)