Bug 1894659 - [devtools] Fix duplicate breakpoints on really long lines r=devtools-reviewers,nchevobbe

`visibleRanges` can return multiple ranges (mostly for large sources the overflow the current viewport),
and those might contain the same line, causing duplicates.
Switching from cm.visibleRanges to cm.viewport

Differential Revision: https://phabricator.services.mozilla.com/D209233
This commit is contained in:
Hubert Boma Manilla 2024-05-07 00:04:16 +00:00
parent 395589a0ca
commit 281aa6bac0

View file

@ -933,31 +933,31 @@ class Editor extends EventEmitter {
// (representing the lines in the current viewport) and generate a new rangeset for updating the line gutter
// based on the conditions defined in the markers(for each line) provided.
const builder = new RangeSetBuilder();
for (const { from, to } of cm.visibleRanges) {
for (let pos = from; pos <= to; ) {
const line = cm.state.doc.lineAt(pos);
for (const {
lineClassName,
condition,
createLineElementNode,
} of markers) {
if (typeof condition !== "function") {
throw new Error("The `condition` is not a valid function");
}
if (condition(line.number)) {
builder.add(
line.from,
line.to,
new LineGutterMarker(
lineClassName,
line.number,
createLineElementNode
)
);
}
const { from, to } = cm.viewport;
let pos = from;
while (pos <= to) {
const line = cm.state.doc.lineAt(pos);
for (const {
lineClassName,
condition,
createLineElementNode,
} of markers) {
if (typeof condition !== "function") {
throw new Error("The `condition` is not a valid function");
}
if (condition(line.number)) {
builder.add(
line.from,
line.to,
new LineGutterMarker(
lineClassName,
line.number,
createLineElementNode
)
);
}
pos = line.to + 1;
}
pos = line.to + 1;
}
// To update the state with the newly generated marker range set, a dispatch is called on the view