diff options
Diffstat (limited to 'devtools/client/debugger/src/utils/location.js')
-rw-r--r-- | devtools/client/debugger/src/utils/location.js | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/devtools/client/debugger/src/utils/location.js b/devtools/client/debugger/src/utils/location.js new file mode 100644 index 0000000000..093b9d7095 --- /dev/null +++ b/devtools/client/debugger/src/utils/location.js @@ -0,0 +1,58 @@ +/* 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/>. */ + +import { getSelectedLocation } from "./selected-location"; + +export function comparePosition(a, b) { + return a && b && a.line == b.line && a.column == b.column; +} + +export function createLocation({ + sourceId, + // Line 0 represents no specific line chosen for action + line = 0, + column, + sourceUrl = "", + sourceActorId = null, +}) { + return { + sourceId, + line, + column, + sourceUrl, + sourceActorId, + }; +} + +export function sortSelectedLocations(locations, selectedSource) { + return Array.from(locations).sort((locationA, locationB) => { + const aSelected = getSelectedLocation(locationA, selectedSource); + const bSelected = getSelectedLocation(locationB, selectedSource); + + // Order the locations by line number… + if (aSelected.line < bSelected.line) { + return -1; + } + + if (aSelected.line > bSelected.line) { + return 1; + } + + // … and if we have the same line, we want to return location with undefined columns + // first, and then order them by column + if (aSelected.column == bSelected.column) { + return 0; + } + + if (aSelected.column === undefined) { + return -1; + } + + if (bSelected.column === undefined) { + return 1; + } + + return aSelected.column < bSelected.column ? -1 : 1; + }); +} |