amis-rpc-design/node_modules/monaco-editor/esm/vs/base/common/range.js

45 lines
1.6 KiB
JavaScript
Raw Normal View History

2023-10-07 19:42:30 +08:00
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
export var Range;
(function (Range) {
/**
* Returns the intersection between two ranges as a range itself.
* Returns `{ start: 0, end: 0 }` if the intersection is empty.
*/
function intersect(one, other) {
if (one.start >= other.end || other.start >= one.end) {
return { start: 0, end: 0 };
}
const start = Math.max(one.start, other.start);
const end = Math.min(one.end, other.end);
if (end - start <= 0) {
return { start: 0, end: 0 };
}
return { start, end };
}
Range.intersect = intersect;
function isEmpty(range) {
return range.end - range.start <= 0;
}
Range.isEmpty = isEmpty;
function intersects(one, other) {
return !isEmpty(intersect(one, other));
}
Range.intersects = intersects;
function relativeComplement(one, other) {
const result = [];
const first = { start: one.start, end: Math.min(other.start, one.end) };
const second = { start: Math.max(other.end, one.start), end: one.end };
if (!isEmpty(first)) {
result.push(first);
}
if (!isEmpty(second)) {
result.push(second);
}
return result;
}
Range.relativeComplement = relativeComplement;
})(Range || (Range = {}));