From 43a97878ce14b72f0981164f87f2e35e14151312 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:22:09 +0200 Subject: Adding upstream version 110.0.1. Signed-off-by: Daniel Baumann --- devtools/client/debugger/src/utils/location.js | 58 ++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 devtools/client/debugger/src/utils/location.js (limited to 'devtools/client/debugger/src/utils/location.js') 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 . */ + +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; + }); +} -- cgit v1.2.3