Minor tweak to locationForRange (#17968)
This commit is contained in:
1 parent
1a93a416d0
commit
ed8e2056f9
1 file changed
+6
-11
@@ -5,27 +5,22 @@ const codeFrameColumnsOptions = {
|
||||
linesBelow: Number.POSITIVE_INFINITY,
|
||||
};
|
||||
|
||||
const locationForRange = (text, rangeStart, rangeEnd) => {
|
||||
if (rangeStart > rangeEnd) {
|
||||
[rangeStart, rangeEnd] = [rangeEnd, rangeStart];
|
||||
}
|
||||
const locationForRange = (text, range) => {
|
||||
const [start, end] = [...range]
|
||||
.sort((indexA, indexB) => indexA - indexB)
|
||||
.map((index) => indexToPosition(text, index, { oneBased: true }));
|
||||
|
||||
const start = indexToPosition(text, rangeStart, { oneBased: true });
|
||||
const end = indexToPosition(text, rangeEnd, { oneBased: true });
|
||||
if (start.line !== end.line) {
|
||||
end.column -= 1;
|
||||
}
|
||||
|
||||
return {
|
||||
start,
|
||||
end,
|
||||
};
|
||||
return { start, end };
|
||||
};
|
||||
|
||||
const visualizeRange = (text, { rangeStart = 0, rangeEnd = text.length }) =>
|
||||
codeFrameColumns(
|
||||
text,
|
||||
locationForRange(text, rangeStart, rangeEnd),
|
||||
locationForRange(text, [rangeStart, rangeEnd]),
|
||||
rangeStart > rangeEnd
|
||||
? { ...codeFrameColumnsOptions, message: "[Reversed range]" }
|
||||
: codeFrameColumnsOptions,
|
||||
|
||||
Reference in new issue
Block a user