continueToHere.js (2047B)
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 import { 6 getSelectedSource, 7 getSelectedFrame, 8 getClosestBreakpointPosition, 9 getBreakpoint, 10 } from "../../selectors/index"; 11 import { createLocation } from "../../utils/location"; 12 import { addHiddenBreakpoint } from "../breakpoints/index"; 13 import { setBreakpointPositions } from "../breakpoints/breakpointPositions"; 14 import { setSkipPausing } from "./skipPausing"; 15 16 import { resume } from "./commands"; 17 18 export function continueToHere(location) { 19 return async function ({ dispatch, getState }) { 20 const { line, column } = location; 21 const selectedSource = getSelectedSource(getState()); 22 const selectedFrame = getSelectedFrame(getState()); 23 24 if (!selectedFrame || !selectedSource) { 25 return; 26 } 27 28 const pausedLine = selectedFrame.location.line; 29 // If the user selects a line to continue to, 30 // it must be different than the currently paused line. 31 if (!column && pausedLine == line) { 32 return; 33 } 34 35 await dispatch(setBreakpointPositions(location)); 36 const position = getClosestBreakpointPosition(getState(), location); 37 38 // If the user selects a location in the editor, 39 // there must be a place we can pause on that line. 40 if (column && !position) { 41 return; 42 } 43 44 const pauseLocation = column && position ? position.location : location; 45 46 // Ensure that breakpoints are enabled while running this 47 await dispatch(setSkipPausing(false)); 48 49 // Set a hidden breakpoint if we do not already have a breakpoint 50 // at the closest position 51 if (!getBreakpoint(getState(), pauseLocation)) { 52 await dispatch( 53 addHiddenBreakpoint( 54 createLocation({ 55 source: selectedSource, 56 line: pauseLocation.line, 57 column: pauseLocation.column, 58 }) 59 ) 60 ); 61 } 62 63 dispatch(resume()); 64 }; 65 }