mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 01:48:05 +00:00
Bug 1591058 - Put the memorization of selected location into togglePrettyPrint() . r=davidwalsh
Now the `togglePrettyPrint` and `selectPrettyLocation` together handle the mapping. mochitest is added. Differential Revision: https://phabricator.services.mozilla.com/D50568 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
d867da8312
commit
f466469108
@ -16,24 +16,27 @@ import {
|
||||
isGenerated,
|
||||
isJavaScript,
|
||||
} from "../../utils/source";
|
||||
import { isFulfilled } from "../../utils/async-value";
|
||||
import { loadSourceText } from "./loadSourceText";
|
||||
import { mapFrames } from "../pause";
|
||||
import { selectSpecificLocation } from "../sources";
|
||||
|
||||
import {
|
||||
getSource,
|
||||
getSourceContent,
|
||||
getSourceFromId,
|
||||
getSourceByURL,
|
||||
getSelectedLocation,
|
||||
getThreadContext,
|
||||
getSourceActorsForSource,
|
||||
} from "../../selectors";
|
||||
|
||||
import type { Action, ThunkArgs } from "../types";
|
||||
import { selectSource } from "./select";
|
||||
import type { Source, SourceContent, SourceActor, Context } from "../../types";
|
||||
import type {
|
||||
Source,
|
||||
SourceContent,
|
||||
SourceActor,
|
||||
Context,
|
||||
SourceLocation,
|
||||
} from "../../types";
|
||||
|
||||
export async function prettyPrintSource(
|
||||
sourceMaps: typeof SourceMaps,
|
||||
@ -84,21 +87,21 @@ export function createPrettySource(cx: Context, sourceId: string) {
|
||||
|
||||
dispatch(({ type: "ADD_SOURCE", cx, source: prettySource }: Action));
|
||||
|
||||
const actors = getSourceActorsForSource(getState(), sourceId);
|
||||
const content = getSourceContent(getState(), sourceId);
|
||||
if (!content || !isFulfilled(content)) {
|
||||
throw new Error("Cannot pretty-print a file that has not loaded");
|
||||
}
|
||||
await prettyPrintSource(sourceMaps, source, content.value, actors);
|
||||
await dispatch(loadSourceText({ cx, source: prettySource }));
|
||||
await dispatch(selectSource(cx, id));
|
||||
|
||||
return prettySource;
|
||||
};
|
||||
}
|
||||
|
||||
function selectPrettyLocation(cx: Context, prettySource: Source) {
|
||||
function selectPrettyLocation(
|
||||
cx: Context,
|
||||
prettySource: Source,
|
||||
generatedLocation: ?SourceLocation
|
||||
) {
|
||||
return async ({ dispatch, sourceMaps, getState }: ThunkArgs) => {
|
||||
let location = getSelectedLocation(getState());
|
||||
let location = generatedLocation
|
||||
? generatedLocation
|
||||
: getSelectedLocation(getState());
|
||||
|
||||
if (location && location.line >= 1) {
|
||||
location = await sourceMaps.getOriginalLocation(location);
|
||||
@ -148,9 +151,9 @@ export function togglePrettyPrint(cx: Context, sourceId: string) {
|
||||
return dispatch(selectPrettyLocation(cx, prettySource));
|
||||
}
|
||||
|
||||
const selectedLocation = getSelectedLocation(getState());
|
||||
const newPrettySource = await dispatch(createPrettySource(cx, sourceId));
|
||||
|
||||
await dispatch(selectPrettyLocation(cx, newPrettySource));
|
||||
dispatch(selectPrettyLocation(cx, newPrettySource, selectedLocation));
|
||||
|
||||
const threadcx = getThreadContext(getState());
|
||||
await dispatch(mapFrames(threadcx));
|
||||
|
@ -62,6 +62,7 @@
|
||||
"waitForSource": false,
|
||||
"waitForLoadedSource": false,
|
||||
"waitForSelectedSource": false,
|
||||
"waitForSelectedLocation": false,
|
||||
"waitForBreakpoint": false,
|
||||
"waitForBreakpointCount": false,
|
||||
"waitForCondition": false,
|
||||
@ -117,6 +118,7 @@
|
||||
"rightClickElement": false,
|
||||
"rightClickEl": false,
|
||||
"clickGutter": false,
|
||||
"countTabs": false,
|
||||
"typeInPanel": false,
|
||||
"selectMenuItem": false,
|
||||
"selectContextMenuItem": false,
|
||||
|
@ -101,6 +101,7 @@ skip-if = (verify && debug && (os == 'mac')) || (os == 'linux' && debug && bits
|
||||
[browser_dbg-pretty-print-breakpoints.js]
|
||||
[browser_dbg-pretty-print-console.js]
|
||||
[browser_dbg-pretty-print-paused.js]
|
||||
[browser_dbg-pretty-print-flow.js]
|
||||
[browser_dbg-preview.js]
|
||||
skip-if = os == "win"
|
||||
[browser_dbg-preview-frame.js]
|
||||
|
@ -0,0 +1,24 @@
|
||||
/* 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/>. */
|
||||
|
||||
// Tests that loader and new tab appear when pretty printing,
|
||||
// and the selected location is mapped afterwards
|
||||
function waitForTabCounts(dbg, counts) {
|
||||
return waitForState(dbg, state => {
|
||||
const tabCounts = countTabs(dbg);
|
||||
|
||||
return tabCounts == counts;
|
||||
});
|
||||
}
|
||||
|
||||
add_task(async function() {
|
||||
const dbg = await initDebugger("doc-pretty.html", "pretty.js");
|
||||
|
||||
await selectSource(dbg, "pretty.js", 4, 8);
|
||||
|
||||
prettyPrint(dbg);
|
||||
await waitForTabCounts(dbg, 2);
|
||||
await waitForElementWithSelector(dbg, selectors.prettyPrintLoader);
|
||||
await waitForSelectedLocation(dbg, 5);
|
||||
});
|
@ -243,10 +243,14 @@ function assertClass(el, className, exists = true) {
|
||||
}
|
||||
}
|
||||
|
||||
function waitForSelectedLocation(dbg, line) {
|
||||
function waitForSelectedLocation(dbg, line, column) {
|
||||
return waitForState(dbg, state => {
|
||||
const location = dbg.selectors.getSelectedLocation();
|
||||
return location && location.line == line;
|
||||
return (
|
||||
location &&
|
||||
(line ? location.line == line : true) &&
|
||||
(column ? location.column == column : true)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@ -715,11 +719,11 @@ function getThreadContext(dbg) {
|
||||
* @return {Promise}
|
||||
* @static
|
||||
*/
|
||||
async function selectSource(dbg, url, line) {
|
||||
async function selectSource(dbg, url, line, column) {
|
||||
const source = findSource(dbg, url);
|
||||
await dbg.actions.selectLocation(
|
||||
getContext(dbg),
|
||||
{ sourceId: source.id, line },
|
||||
{ sourceId: source.id, line, column },
|
||||
{ keepContext: false }
|
||||
);
|
||||
return waitForSelectedSource(dbg, url);
|
||||
@ -1315,6 +1319,7 @@ const selectors = {
|
||||
replayNext: ".replay-next.active",
|
||||
toggleBreakpoints: ".breakpoints-toggle",
|
||||
prettyPrintButton: ".source-footer .prettyPrint",
|
||||
prettyPrintLoader: ".source-footer .spin",
|
||||
sourceMapLink: ".source-footer .mapped-source",
|
||||
sourcesFooter: ".sources-panel .source-footer",
|
||||
editorFooter: ".editor-pane .source-footer",
|
||||
|
Loading…
Reference in New Issue
Block a user